Remove X funcs and add G funcs

This commit is contained in:
Patrick O'brien 2016-08-01 15:10:10 +10:00
parent edecf1b704
commit 2d732c727a
17 changed files with 183 additions and 183 deletions

View file

@ -1,31 +1,31 @@
{{- define "relationship_to_one_helper"}} {{- define "relationship_to_one_helper"}}
// {{.Function.Name}}G pointed to by the foreign key.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}G(selectCols ...string) (*{{.ForeignTable.NameGo}}, error) {
return {{.Function.Receiver}}.{{.Function.Name}}(boil.GetDB(), selectCols...)
}
// {{.Function.Name}}GP pointed to by the foreign key. Panics on error.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}GP(selectCols ...string) *{{.ForeignTable.NameGo}} {
o, err := {{.Function.Receiver}}.{{.Function.Name}}(boil.GetDB(), selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// {{.Function.Name}}P pointed to by the foreign key with exeuctor. Panics on error.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}P(exec boil.Executor, selectCols ...string) *{{.ForeignTable.NameGo}} {
o, err := {{.Function.Receiver}}.{{.Function.Name}}(exec, selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// {{.Function.Name}} pointed to by the foreign key. // {{.Function.Name}} pointed to by the foreign key.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}(selectCols ...string) (*{{.ForeignTable.NameGo}}, error) { func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}(exec boil.Executor, selectCols ...string) (*{{.ForeignTable.NameGo}}, error) {
return {{.Function.Receiver}}.{{.Function.Name}}X(boil.GetDB(), selectCols...)
}
// {{.Function.Name}}P pointed to by the foreign key. Panics on error.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}P(selectCols ...string) *{{.ForeignTable.NameGo}} {
o, err := {{.Function.Receiver}}.{{.Function.Name}}X(boil.GetDB(), selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// {{.Function.Name}}XP pointed to by the foreign key with exeuctor. Panics on error.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}XP(exec boil.Executor, selectCols ...string) *{{.ForeignTable.NameGo}} {
o, err := {{.Function.Receiver}}.{{.Function.Name}}X(exec, selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// {{.Function.Name}}X pointed to by the foreign key.
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}X(exec boil.Executor, selectCols ...string) (*{{.ForeignTable.NameGo}}, error) {
{{.Function.Varname}} := &{{.ForeignTable.NameGo}}{} {{.Function.Varname}} := &{{.ForeignTable.NameGo}}{}
selectColumns := `*` selectColumns := `*`

View file

@ -7,16 +7,16 @@
{{- template "relationship_to_one_helper" (textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table .) -}} {{- template "relationship_to_one_helper" (textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table .) -}}
{{- else -}} {{- else -}}
{{- $rel := textsFromRelationship $dot.Tables $table . -}} {{- $rel := textsFromRelationship $dot.Tables $table . -}}
// {{$rel.Function.Name}} retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} // {{$rel.Function.Name}}G retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}}
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}(selectCols ...string) ({{$rel.ForeignTable.Slice}}, error) { func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}G(selectCols ...string) ({{$rel.ForeignTable.Slice}}, error) {
return {{$rel.Function.Receiver}}.{{$rel.Function.Name}}X(boil.GetDB(), selectCols...) return {{$rel.Function.Receiver}}.{{$rel.Function.Name}}(boil.GetDB(), selectCols...)
} }
// {{$rel.Function.Name}}P panics on error. Retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} // {{$rel.Function.Name}}GP panics on error. Retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}}
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}P(selectCols ...string) {{$rel.ForeignTable.Slice}} { func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}GP(selectCols ...string) {{$rel.ForeignTable.Slice}} {
o, err := {{$rel.Function.Receiver}}.{{$rel.Function.Name}}X(boil.GetDB(), selectCols...) o, err := {{$rel.Function.Receiver}}.{{$rel.Function.Name}}(boil.GetDB(), selectCols...)
if err != nil { if err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
@ -24,10 +24,10 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
return o return o
} }
// {{$rel.Function.Name}}XP panics on error. Retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} with an executor // {{$rel.Function.Name}}P panics on error. Retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} with an executor
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}XP(exec boil.Executor, selectCols ...string) {{$rel.ForeignTable.Slice}} { func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}P(exec boil.Executor, selectCols ...string) {{$rel.ForeignTable.Slice}} {
o, err := {{$rel.Function.Receiver}}.{{$rel.Function.Name}}X(exec, selectCols...) o, err := {{$rel.Function.Receiver}}.{{$rel.Function.Name}}(exec, selectCols...)
if err != nil { if err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
@ -35,9 +35,9 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
return o return o
} }
// {{$rel.Function.Name}}X retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} with an executor // {{$rel.Function.Name}} retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} with an executor
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}X(exec boil.Executor, selectCols ...string) ({{$rel.ForeignTable.Slice}}, error) { func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}(exec boil.Executor, selectCols ...string) ({{$rel.ForeignTable.Slice}}, error) {
var ret {{$rel.ForeignTable.Slice}} var ret {{$rel.ForeignTable.Slice}}
selectColumns := `"{{id 0}}".*` selectColumns := `"{{id 0}}".*`

View file

@ -1,13 +1,13 @@
{{- $tableNameSingular := .Table.Name | singular | titleCase -}} {{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}} {{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}} {{- $varNameSingular := .Table.Name | singular | camelCase -}}
// {{$tableNamePlural}}All retrieves all records. // {{$tableNamePlural}}G retrieves all records.
func {{$tableNamePlural}}(mods ...qm.QueryMod) {{$varNameSingular}}Query { func {{$tableNamePlural}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
return {{$tableNamePlural}}X(boil.GetDB(), mods...) return {{$tableNamePlural}}(boil.GetDB(), mods...)
} }
// {{$tableNamePlural}}X retrieves all the records using an executor. // {{$tableNamePlural}} retrieves all the records using an executor.
func {{$tableNamePlural}}X(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query { func {{$tableNamePlural}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query {
mods = append(mods, qm.Table("{{.Table.Name}}")) mods = append(mods, qm.From("{{.Table.Name}}"))
return {{$varNameSingular}}Query{NewQueryX(exec, mods...)} return {{$varNameSingular}}Query{NewQuery(exec, mods...)}
} }

View file

@ -4,14 +4,14 @@
{{- $colDefs := sqlColDefinitions .Table.Columns .Table.PKey.Columns -}} {{- $colDefs := sqlColDefinitions .Table.Columns .Table.PKey.Columns -}}
{{- $pkNames := $colDefs.Names | stringMap .StringFuncs.camelCase -}} {{- $pkNames := $colDefs.Names | stringMap .StringFuncs.camelCase -}}
{{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}} {{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}}
// {{$tableNameSingular}}Find retrieves a single record by ID. // {{$tableNameSingular}}FindG retrieves a single record by ID.
func {{$tableNameSingular}}Find({{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) { func {{$tableNameSingular}}FindG({{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
return {{$tableNameSingular}}FindX(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...) return {{$tableNameSingular}}Find(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...)
} }
// {{$tableNameSingular}}FindP retrieves a single record by ID, and panics on error. // {{$tableNameSingular}}FindGP retrieves a single record by ID, and panics on error.
func {{$tableNameSingular}}FindP({{$pkArgs}}, selectCols ...string) *{{$tableNameSingular}} { func {{$tableNameSingular}}FindGP({{$pkArgs}}, selectCols ...string) *{{$tableNameSingular}} {
o, err := {{$tableNameSingular}}FindX(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...) o, err := {{$tableNameSingular}}Find(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...)
if err != nil { if err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
@ -19,17 +19,17 @@ func {{$tableNameSingular}}FindP({{$pkArgs}}, selectCols ...string) *{{$tableNam
return o return o
} }
// {{$tableNameSingular}}FindX retrieves a single record by ID with an executor. // {{$tableNameSingular}}Find retrieves a single record by ID with an executor.
func {{$tableNameSingular}}FindX(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) { func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
{{$varNameSingular}} := &{{$tableNameSingular}}{} {{$varNameSingular}} := &{{$tableNameSingular}}{}
mods := []qm.QueryMod{ mods := []qm.QueryMod{
qm.Select(selectCols...), qm.Select(selectCols...),
qm.Table("{{.Table.Name}}"), qm.From("{{.Table.Name}}"),
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{$pkNames | join ", "}}), qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{$pkNames | join ", "}}),
} }
q := NewQueryX(exec, mods...) q := NewQuery(exec, mods...)
err := boil.ExecQueryOne(q).Scan(boil.GetStructPointers({{$varNameSingular}}, selectCols...)...) err := boil.ExecQueryOne(q).Scan(boil.GetStructPointers({{$varNameSingular}}, selectCols...)...)
@ -40,9 +40,9 @@ func {{$tableNameSingular}}FindX(exec boil.Executor, {{$pkArgs}}, selectCols ...
return {{$varNameSingular}}, nil return {{$varNameSingular}}, nil
} }
// {{$tableNameSingular}}FindXP retrieves a single record by ID with an executor, and panics on error. // {{$tableNameSingular}}FindP retrieves a single record by ID with an executor, and panics on error.
func {{$tableNameSingular}}FindXP(exec boil.Executor, {{$pkArgs}}, selectCols ...string) *{{$tableNameSingular}} { func {{$tableNameSingular}}FindP(exec boil.Executor, {{$pkArgs}}, selectCols ...string) *{{$tableNameSingular}} {
o, err := {{$tableNameSingular}}FindX(exec, {{$pkNames | join ", "}}, selectCols...) o, err := {{$tableNameSingular}}Find(exec, {{$pkNames | join ", "}}, selectCols...)
if err != nil { if err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }

View file

@ -1,19 +1,19 @@
{{- $tableNameSingular := .Table.Name | singular | titleCase -}} {{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}} {{- $varNameSingular := .Table.Name | singular | camelCase -}}
// Insert a single record. // InsertG a single record.
func (o *{{$tableNameSingular}}) Insert(whitelist ... string) error { func (o *{{$tableNameSingular}}) InsertG(whitelist ... string) error {
return o.InsertX(boil.GetDB(), whitelist...) return o.Insert(boil.GetDB(), whitelist...)
} }
// InsertP a single record, and panics on error. // InsertGP a single record, and panics on error.
func (o *{{$tableNameSingular}}) InsertP(whitelist ... string) { func (o *{{$tableNameSingular}}) InsertGP(whitelist ... string) {
if err := o.InsertX(boil.GetDB(), whitelist...); err != nil { if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
// InsertX a single record using an executor. // Insert a single record using an executor.
func (o *{{$tableNameSingular}}) InsertX(exec boil.Executor, whitelist ... string) error { func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string) error {
if o == nil { if o == nil {
return errors.New("{{.PkgName}}: no {{.Table.Name}} provided for insertion") return errors.New("{{.PkgName}}: no {{.Table.Name}} provided for insertion")
} }
@ -81,9 +81,9 @@ func (o *{{$tableNameSingular}}) InsertX(exec boil.Executor, whitelist ... strin
return nil return nil
} }
// InsertXP a single record using an executor, and panics on error. // InsertP a single record using an executor, and panics on error.
func (o *{{$tableNameSingular}}) InsertXP(exec boil.Executor, whitelist ... string) { func (o *{{$tableNameSingular}}) InsertP(exec boil.Executor, whitelist ... string) {
if err := o.InsertX(exec, whitelist...); err != nil { if err := o.Insert(exec, whitelist...); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }

View file

@ -3,50 +3,50 @@
{{- $colDefs := sqlColDefinitions .Table.Columns .Table.PKey.Columns -}} {{- $colDefs := sqlColDefinitions .Table.Columns .Table.PKey.Columns -}}
{{- $pkNames := $colDefs.Names | stringMap .StringFuncs.camelCase -}} {{- $pkNames := $colDefs.Names | stringMap .StringFuncs.camelCase -}}
{{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}} {{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}}
// Update a single {{$tableNameSingular}} record. // UpdateG a single {{$tableNameSingular}} record.
// Update takes a whitelist of column names that should be updated. // UpdateG takes a whitelist of column names that should be updated.
// The primary key will be used to find the record to update. // The primary key will be used to find the record to update.
func (o *{{$tableNameSingular}}) Update(whitelist ...string) error { func (o *{{$tableNameSingular}}) UpdateG(whitelist ...string) error {
return o.UpdateX(boil.GetDB(), whitelist...) return o.Update(boil.GetDB(), whitelist...)
} }
// Update a single {{$tableNameSingular}} record. // UpdateGP a single {{$tableNameSingular}} record.
// UpdateP takes a whitelist of column names that should be updated. // UpdateGP takes a whitelist of column names that should be updated.
// The primary key will be used to find the record to update. // The primary key will be used to find the record to update.
// Panics on error. // Panics on error.
func (o *{{$tableNameSingular}}) UpdateP(whitelist ...string) { func (o *{{$tableNameSingular}}) UpdateGP(whitelist ...string) {
if err := o.UpdateX(boil.GetDB(), whitelist...); err != nil { if err := o.Update(boil.GetDB(), whitelist...); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
// UpdateX uses an executor to update the {{$tableNameSingular}}. // Update uses an executor to update the {{$tableNameSingular}}.
func (o *{{$tableNameSingular}}) UpdateX(exec boil.Executor, whitelist ... string) error { func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string) error {
return o.UpdateAtX(exec, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}, whitelist...) return o.UpdateAt(exec, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}, whitelist...)
} }
// UpdateXP uses an executor to update the {{$tableNameSingular}}, and panics on error. // UpdateP uses an executor to update the {{$tableNameSingular}}, and panics on error.
func (o *{{$tableNameSingular}}) UpdateXP(exec boil.Executor, whitelist ... string) { func (o *{{$tableNameSingular}}) UpdateP(exec boil.Executor, whitelist ... string) {
err := o.UpdateAtX(exec, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}, whitelist...) err := o.UpdateAt(exec, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}, whitelist...)
if err != nil { if err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
// UpdateAt updates the {{$tableNameSingular}} using the primary key to find the row to update. // UpdateAtG updates the {{$tableNameSingular}} using the primary key to find the row to update.
func (o *{{$tableNameSingular}}) UpdateAt({{$pkArgs}}, whitelist ...string) error { func (o *{{$tableNameSingular}}) UpdateAtG({{$pkArgs}}, whitelist ...string) error {
return o.UpdateAtX(boil.GetDB(), {{$pkNames | join ", "}}, whitelist...) return o.UpdateAt(boil.GetDB(), {{$pkNames | join ", "}}, whitelist...)
} }
// UpdateAtP updates the {{$tableNameSingular}} using the primary key to find the row to update. Panics on error. // UpdateAtGP updates the {{$tableNameSingular}} using the primary key to find the row to update. Panics on error.
func (o *{{$tableNameSingular}}) UpdateAtP({{$pkArgs}}, whitelist ...string) { func (o *{{$tableNameSingular}}) UpdateAtGP({{$pkArgs}}, whitelist ...string) {
if err := o.UpdateAtX(boil.GetDB(), {{$pkNames | join ", "}}, whitelist...); err != nil { if err := o.UpdateAt(boil.GetDB(), {{$pkNames | join ", "}}, whitelist...); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
// UpdateAtX uses an executor to update the {{$tableNameSingular}} using the primary key to find the row to update. // UpdateAt uses an executor to update the {{$tableNameSingular}} using the primary key to find the row to update.
func (o *{{$tableNameSingular}}) UpdateAtX(exec boil.Executor, {{$pkArgs}}, whitelist ...string) error { func (o *{{$tableNameSingular}}) UpdateAt(exec boil.Executor, {{$pkArgs}}, whitelist ...string) error {
if err := o.doBeforeUpdateHooks(); err != nil { if err := o.doBeforeUpdateHooks(); err != nil {
return err return err
} }
@ -82,10 +82,10 @@ func (o *{{$tableNameSingular}}) UpdateAtX(exec boil.Executor, {{$pkArgs}}, whit
return nil return nil
} }
// UpdateAtXP uses an executor to update the {{$tableNameSingular}} using the primary key to find the row to update. // UpdateAtP uses an executor to update the {{$tableNameSingular}} using the primary key to find the row to update.
// Panics on error. // Panics on error.
func (o *{{$tableNameSingular}}) UpdateAtXP(exec boil.Executor, {{$pkArgs}}, whitelist ...string) { func (o *{{$tableNameSingular}}) UpdateAtP(exec boil.Executor, {{$pkArgs}}, whitelist ...string) {
if err := o.UpdateAtX(exec, {{$pkNames | join ", "}}, whitelist...); err != nil { if err := o.UpdateAt(exec, {{$pkNames | join ", "}}, whitelist...); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }

View file

@ -1,27 +1,27 @@
{{- $tableNameSingular := .Table.Name | singular | titleCase -}} {{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}} {{- $varNameSingular := .Table.Name | singular | camelCase -}}
// Delete deletes a single {{$tableNameSingular}} record. // DeleteG deletes a single {{$tableNameSingular}} record.
// Delete will match against the primary key column to find the record to delete. // DeleteG will match against the primary key column to find the record to delete.
func (o *{{$tableNameSingular}}) Delete() error { func (o *{{$tableNameSingular}}) DeleteG() error {
if o == nil { if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion") return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion")
} }
return o.DeleteX(boil.GetDB()) return o.Delete(boil.GetDB())
} }
// DeleteP deletes a single {{$tableNameSingular}} record. // DeleteGP deletes a single {{$tableNameSingular}} record.
// DeleteP will match against the primary key column to find the record to delete. // DeleteGP will match against the primary key column to find the record to delete.
// Panics on error. // Panics on error.
func (o *{{$tableNameSingular}}) DeleteP() { func (o *{{$tableNameSingular}}) DeleteGP() {
if err := o.Delete(); err != nil { if err := o.DeleteG(); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
// DeleteX deletes a single {{$tableNameSingular}} record with an executor. // Delete deletes a single {{$tableNameSingular}} record with an executor.
// DeleteX will match against the primary key column to find the record to delete. // Delete will match against the primary key column to find the record to delete.
func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error { func (o *{{$tableNameSingular}}) Delete(exec boil.Executor) error {
if o == nil { if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion") return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion")
} }
@ -29,11 +29,11 @@ func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error {
var mods []qm.QueryMod var mods []qm.QueryMod
mods = append(mods, mods = append(mods,
qm.Table("{{.Table.Name}}"), qm.From("{{.Table.Name}}"),
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}), qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}),
) )
query := NewQueryX(exec, mods...) query := NewQuery(exec, mods...)
boil.SetDelete(query) boil.SetDelete(query)
_, err := boil.ExecQuery(query) _, err := boil.ExecQuery(query)
@ -44,11 +44,11 @@ func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error {
return nil return nil
} }
// DeleteXP deletes a single {{$tableNameSingular}} record with an executor. // DeleteP deletes a single {{$tableNameSingular}} record with an executor.
// DeleteXP will match against the primary key column to find the record to delete. // DeleteP will match against the primary key column to find the record to delete.
// Panics on error. // Panics on error.
func (o *{{$tableNameSingular}}) DeleteXP(exec boil.Executor) { func (o *{{$tableNameSingular}}) DeleteP(exec boil.Executor) {
if err := o.DeleteX(exec); err != nil { if err := o.Delete(exec); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
@ -76,23 +76,23 @@ func (o {{$varNameSingular}}Query) DeleteAllP() {
} }
} }
// DeleteAll deletes all rows in the slice. // DeleteAll deletes all rows in the slice, and panics on error.
func (o {{$tableNameSingular}}Slice) DeleteAll() error { func (o {{$tableNameSingular}}Slice) DeleteAllGP() {
if o == nil { if err := o.DeleteAllG(); err != nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
}
return o.DeleteAllX(boil.GetDB())
}
// DeleteAll deletes all rows in the slice.
func (o {{$tableNameSingular}}Slice) DeleteAllP() {
if err := o.DeleteAll(); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }
// DeleteAllX deletes all rows in the slice with an executor. // DeleteAllG deletes all rows in the slice.
func (o {{$tableNameSingular}}Slice) DeleteAllX(exec boil.Executor) error { func (o {{$tableNameSingular}}Slice) DeleteAllG() error {
if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
}
return o.DeleteAll(boil.GetDB())
}
// DeleteAll deletes all rows in the slice with an executor.
func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
if o == nil { if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all") return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
} }
@ -103,11 +103,11 @@ func (o {{$tableNameSingular}}Slice) DeleteAllX(exec boil.Executor) error {
in := boil.WherePrimaryKeyIn(len(o), {{.Table.PKey.Columns | stringMap .StringFuncs.quoteWrap | join ", "}}) in := boil.WherePrimaryKeyIn(len(o), {{.Table.PKey.Columns | stringMap .StringFuncs.quoteWrap | join ", "}})
mods = append(mods, mods = append(mods,
qm.Table("{{.Table.Name}}"), qm.From("{{.Table.Name}}"),
qm.Where(in, args...), qm.Where(in, args...),
) )
query := NewQueryX(exec, mods...) query := NewQuery(exec, mods...)
boil.SetDelete(query) boil.SetDelete(query)
_, err := boil.ExecQuery(query) _, err := boil.ExecQuery(query)
@ -121,9 +121,9 @@ func (o {{$tableNameSingular}}Slice) DeleteAllX(exec boil.Executor) error {
return nil return nil
} }
// DeleteAllXP deletes all rows in the slice with an executor, and panics on error. // DeleteAllP deletes all rows in the slice with an executor, and panics on error.
func (o {{$tableNameSingular}}Slice) DeleteAllXP(exec boil.Executor) { func (o {{$tableNameSingular}}Slice) DeleteAllP(exec boil.Executor) {
if err := o.DeleteAllX(exec); err != nil { if err := o.DeleteAll(exec); err != nil {
panic(boil.WrapErr(err)) panic(boil.WrapErr(err))
} }
} }

View file

@ -1,13 +1,13 @@
// M type is for providing where filters to Where helpers. // M type is for providing where filters to Where helpers.
type M map[string]interface{} type M map[string]interface{}
// NewQuery initializes a new Query using the passed in QueryMods // NewQueryG initializes a new Query using the passed in QueryMods
func NewQuery(mods ...qm.QueryMod) *boil.Query { func NewQueryG(mods ...qm.QueryMod) *boil.Query {
return NewQueryX(boil.GetDB(), mods...) return NewQuery(boil.GetDB(), mods...)
} }
// NewQueryX initializes a new Query using the passed in QueryMods // NewQuery initializes a new Query using the passed in QueryMods
func NewQueryX(exec boil.Executor, mods ...qm.QueryMod) *boil.Query { func NewQuery(exec boil.Executor, mods ...qm.QueryMod) *boil.Query {
q := &boil.Query{} q := &boil.Query{}
boil.SetExecutor(q, exec) boil.SetExecutor(q, exec)
qm.Apply(q, mods...) qm.Apply(q, mods...)

View file

@ -13,21 +13,21 @@ func Test{{$tableNamePlural}}(t *testing.T) {
// insert two random objects to test DeleteAll // insert two random objects to test DeleteAll
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
// Delete all rows to give a clean slate // Delete all rows to give a clean slate
err = {{$tableNamePlural}}().DeleteAll() err = {{$tableNamePlural}}G().DeleteAll()
if err != nil { if err != nil {
t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err) t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err)
} }
// Check number of rows in table to ensure DeleteAll was successful // Check number of rows in table to ensure DeleteAll was successful
var c int64 var c int64
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 0 { if c != 0 {
t.Errorf("Expected {{.Table.Name}} table to be empty, but got %d rows", c) t.Errorf("Expected {{.Table.Name}} table to be empty, but got %d rows", c)
@ -39,20 +39,20 @@ func Test{{$tableNamePlural}}(t *testing.T) {
} }
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
// Ensure Count is valid // Ensure Count is valid
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 3 { if c != 3 {
t.Errorf("Expected {{.Table.Name}} table to have 3 rows, but got %d", c) t.Errorf("Expected {{.Table.Name}} table to have 3 rows, but got %d", c)
} }
// Attempt to retrieve all objects // Attempt to retrieve all objects
res, err := {{$tableNamePlural}}().All() res, err := {{$tableNamePlural}}G().All()
if err != nil { if err != nil {
t.Errorf("Unable to retrieve all {{$tableNamePlural}}, err: %s", err) t.Errorf("Unable to retrieve all {{$tableNamePlural}}, err: %s", err)
} }

View file

@ -5,7 +5,7 @@
{{- $varNameSingular := .Table.Name | singular | camelCase -}} {{- $varNameSingular := .Table.Name | singular | camelCase -}}
func {{$varNamePlural}}DeleteAllRows(t *testing.T) { func {{$varNamePlural}}DeleteAllRows(t *testing.T) {
// Delete all rows to give a clean slate // Delete all rows to give a clean slate
err := {{$tableNamePlural}}().DeleteAll() err := {{$tableNamePlural}}G().DeleteAll()
if err != nil { if err != nil {
t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err) t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err)
} }
@ -19,7 +19,7 @@ func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
{{$varNamePlural}}DeleteAllRows(t) {{$varNamePlural}}DeleteAllRows(t)
// Check number of rows in table to ensure DeleteAll was successful // Check number of rows in table to ensure DeleteAll was successful
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 0 { if c != 0 {
t.Errorf("Expected 0 rows after ObjDeleteAllRows() call, but got %d rows", c) t.Errorf("Expected 0 rows after ObjDeleteAllRows() call, but got %d rows", c)
@ -32,20 +32,20 @@ func Test{{$tableNamePlural}}QueryDeleteAll(t *testing.T) {
// insert random columns to test DeleteAll // insert random columns to test DeleteAll
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
// Test DeleteAll() query function // Test DeleteAll() query function
err = {{$tableNamePlural}}().DeleteAll() err = {{$tableNamePlural}}G().DeleteAll()
if err != nil { if err != nil {
t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err) t.Errorf("Unable to delete all from {{$tableNamePlural}}: %s", err)
} }
// Check number of rows in table to ensure DeleteAll was successful // Check number of rows in table to ensure DeleteAll was successful
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 0 { if c != 0 {
t.Errorf("Expected 0 rows after Obj().DeleteAll() call, but got %d rows", c) t.Errorf("Expected 0 rows after Obj().DeleteAll() call, but got %d rows", c)
@ -63,19 +63,19 @@ func Test{{$tableNamePlural}}SliceDeleteAll(t *testing.T) {
} }
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
// test DeleteAll slice function // test DeleteAll slice function
if err = o.DeleteAll(); err != nil { if err = o.DeleteAllG(); err != nil {
t.Errorf("Unable to objSlice.DeleteAll(): %s", err) t.Errorf("Unable to objSlice.DeleteAll(): %s", err)
} }
// Check number of rows in table to ensure DeleteAll was successful // Check number of rows in table to ensure DeleteAll was successful
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 0 { if c != 0 {
t.Errorf("Expected 0 rows after objSlice.DeleteAll() call, but got %d rows", c) t.Errorf("Expected 0 rows after objSlice.DeleteAll() call, but got %d rows", c)
@ -93,26 +93,26 @@ func Test{{$tableNamePlural}}Delete(t *testing.T) {
} }
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
o[0].Delete() o[0].DeleteG()
// Check number of rows in table to ensure DeleteAll was successful // Check number of rows in table to ensure DeleteAll was successful
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 2 { if c != 2 {
t.Errorf("Expected 2 rows after obj.Delete() call, but got %d rows", c) t.Errorf("Expected 2 rows after obj.Delete() call, but got %d rows", c)
} }
o[1].Delete() o[1].DeleteG()
o[2].Delete() o[2].DeleteG()
// Check number of rows in table to ensure Delete worked for all rows // Check number of rows in table to ensure Delete worked for all rows
c, err = {{$tableNamePlural}}().Count() c, err = {{$tableNamePlural}}G().Count()
if c != 0 { if c != 0 {
t.Errorf("Expected 0 rows after all obj.Delete() calls, but got %d rows", c) t.Errorf("Expected 0 rows after all obj.Delete() calls, but got %d rows", c)

View file

@ -12,7 +12,7 @@ func Test{{$tableNamePlural}}Find(t *testing.T) {
} }
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
if err = o[i].Insert(); err != nil { if err = o[i].InsertG(); err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
@ -20,11 +20,11 @@ func Test{{$tableNamePlural}}Find(t *testing.T) {
j := make({{$tableNameSingular}}Slice, 3) j := make({{$tableNameSingular}}Slice, 3)
// Perform all Find queries and assign result objects to slice for comparison // Perform all Find queries and assign result objects to slice for comparison
for i := 0; i < len(j); i++ { for i := 0; i < len(j); i++ {
j[i], err = {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[i]." | join ", "}}) j[i], err = {{$tableNameSingular}}FindG({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[i]." | join ", "}})
{{$varNameSingular}}CompareVals(o[i], j[i], t) {{$varNameSingular}}CompareVals(o[i], j[i], t)
} }
f, err := {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[0]." | join ", "}}, {{$varNameSingular}}PrimaryKeyColumns...) f, err := {{$tableNameSingular}}FindG({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[0]." | join ", "}}, {{$varNameSingular}}PrimaryKeyColumns...)
{{range $key, $value := .Table.PKey.Columns}} {{range $key, $value := .Table.PKey.Columns}}
if o[0].{{titleCase $value}} != f.{{titleCase $value}} { if o[0].{{titleCase $value}} != f.{{titleCase $value}} {
t.Errorf("Expected primary key values to match, {{titleCase $value}} did not match") t.Errorf("Expected primary key values to match, {{titleCase $value}} did not match")

View file

@ -11,13 +11,13 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
if err = o.Insert(); err != nil { if err = o.InsertG(); err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o, err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o, err)
} }
j := {{$tableNameSingular}}{} j := {{$tableNameSingular}}{}
err = {{$tableNamePlural}}(qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})).Bind(&j) err = {{$tableNamePlural}}G(qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})).Bind(&j)
if err != nil { if err != nil {
t.Errorf("Unable to call Bind on {{$tableNameSingular}} single object: %s", err) t.Errorf("Unable to call Bind on {{$tableNameSingular}} single object: %s", err)
} }
@ -34,14 +34,14 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
// insert random columns to test DeleteAll // insert random columns to test DeleteAll
for i := 0; i < len(y); i++ { for i := 0; i < len(y); i++ {
err = y[i].Insert() err = y[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", y[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", y[i], err)
} }
} }
k := {{$tableNameSingular}}Slice{} k := {{$tableNameSingular}}Slice{}
err = {{$tableNamePlural}}().Bind(&k) err = {{$tableNamePlural}}G().Bind(&k)
if err != nil { if err != nil {
t.Errorf("Unable to call Bind on {{$tableNameSingular}} slice of objects: %s", err) t.Errorf("Unable to call Bind on {{$tableNameSingular}} slice of objects: %s", err)
} }
@ -65,11 +65,11 @@ func Test{{$tableNamePlural}}One(t *testing.T) {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
if err = o.Insert(); err != nil { if err = o.InsertG(); err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o, err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o, err)
} }
j, err := {{$tableNamePlural}}().One() j, err := {{$tableNamePlural}}G().One()
if err != nil { if err != nil {
t.Errorf("Unable to fetch One {{$tableNameSingular}} result:\n#%v\nErr: %s", j, err) t.Errorf("Unable to fetch One {{$tableNameSingular}} result:\n#%v\nErr: %s", j, err)
} }
@ -89,13 +89,13 @@ func Test{{$tableNamePlural}}All(t *testing.T) {
// insert random columns to test DeleteAll // insert random columns to test DeleteAll
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
j, err := {{$tableNamePlural}}().All() j, err := {{$tableNamePlural}}G().All()
if err != nil { if err != nil {
t.Errorf("Unable to fetch All {{$tableNameSingular}} results: %s", err) t.Errorf("Unable to fetch All {{$tableNameSingular}} results: %s", err)
} }
@ -121,13 +121,13 @@ func Test{{$tableNamePlural}}Count(t *testing.T) {
// insert random columns to test Count // insert random columns to test Count
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
err = o[i].Insert() err = o[i].InsertG()
if err != nil { if err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
c, err := {{$tableNamePlural}}().Count() c, err := {{$tableNamePlural}}G().Count()
if err != nil { if err != nil {
t.Errorf("Unable to count query {{$tableNameSingular}}: %s", err) t.Errorf("Unable to count query {{$tableNameSingular}}: %s", err)
} }

View file

@ -22,7 +22,7 @@ func Test{{$tableNamePlural}}Insert(t *testing.T) {
} }
for i := 0; i < len(o); i++ { for i := 0; i < len(o); i++ {
if err = o[i].Insert(); err != nil { if err = o[i].InsertG(); err != nil {
t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err) t.Errorf("Unable to insert {{$tableNameSingular}}:\n%#v\nErr: %s", o[i], err)
} }
} }
@ -30,14 +30,14 @@ func Test{{$tableNamePlural}}Insert(t *testing.T) {
j := make({{$tableNameSingular}}Slice, 3) j := make({{$tableNameSingular}}Slice, 3)
// Perform all Find queries and assign result objects to slice for comparison // Perform all Find queries and assign result objects to slice for comparison
for i := 0; i < len(j); i++ { for i := 0; i < len(j); i++ {
j[i], err = {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[i]." | join ", "}}) j[i], err = {{$tableNameSingular}}FindG({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o[i]." | join ", "}})
{{$varNameSingular}}CompareVals(o[i], j[i], t) {{$varNameSingular}}CompareVals(o[i], j[i], t)
} }
{{$varNamePlural}}DeleteAllRows(t) {{$varNamePlural}}DeleteAllRows(t)
item := &{{$tableNameSingular}}{} item := &{{$tableNameSingular}}{}
if err = item.Insert(); err != nil { if err = item.InsertG(); err != nil {
t.Errorf("Unable to insert zero-value item {{$tableNameSingular}}:\n%#v\nErr: %s", item, err) t.Errorf("Unable to insert zero-value item {{$tableNameSingular}}:\n%#v\nErr: %s", item, err)
} }

View file

@ -15,7 +15,7 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
var a {{$rel.LocalTable.NameGo}} var a {{$rel.LocalTable.NameGo}}
var b, c {{$rel.ForeignTable.NameGo}} var b, c {{$rel.ForeignTable.NameGo}}
if err := a.InsertX(tx); err != nil { if err := a.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -32,10 +32,10 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
b.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}} b.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}}
c.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}} c.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}}
{{- end}} {{- end}}
if err = b.InsertX(tx); err != nil { if err = b.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err = c.InsertX(tx); err != nil { if err = c.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -51,7 +51,7 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
{{end}} {{end}}
{{$varname := $rel.ForeignTable.NamePluralGo | toLower -}} {{$varname := $rel.ForeignTable.NamePluralGo | toLower -}}
{{$varname}}, err := a.{{$rel.Function.Name}}X(tx) {{$varname}}, err := a.{{$rel.Function.Name}}(tx)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -14,26 +14,26 @@ func Test{{.LocalTable.NameGo}}ToOne{{.ForeignTable.NameGo}}_{{.Function.Name}}(
{{if not .Function.ReverseInserts -}} {{if not .Function.ReverseInserts -}}
if err := foreign.InsertX(tx); err != nil { if err := foreign.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
local.{{.Function.LocalAssignment}} = foreign.{{.Function.ForeignAssignment}} local.{{.Function.LocalAssignment}} = foreign.{{.Function.ForeignAssignment}}
if err := local.InsertX(tx); err != nil { if err := local.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
{{else -}} {{else -}}
if err := local.InsertX(tx); err != nil { if err := local.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
foreign.{{.Function.ForeignAssignment}} = local.{{.Function.LocalAssignment}} foreign.{{.Function.ForeignAssignment}} = local.{{.Function.LocalAssignment}}
if err := foreign.InsertX(tx); err != nil { if err := foreign.Insert(tx); err != nil {
t.Fatal(err) t.Fatal(err)
} }
{{end -}} {{end -}}
check, err := local.{{.Function.Name}}X(tx) check, err := local.{{.Function.Name}}(tx)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -26,11 +26,11 @@ func Test{{$tableNamePlural}}Select(t *testing.T) {
t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err) t.Errorf("Unable to randomize {{$tableNameSingular}} struct: %s", err)
} }
if err = item.Insert(); err != nil { if err = item.InsertG(); err != nil {
t.Errorf("Unable to insert item {{$tableNameSingular}}:\n%#v\nErr: %s", item, err) t.Errorf("Unable to insert item {{$tableNameSingular}}:\n%#v\nErr: %s", item, err)
} }
err = {{$tableNamePlural}}(qm.Select({{$varNameSingular}}AutoIncrementColumns...), qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "item." | join ", "}})).Bind(x) err = {{$tableNamePlural}}G(qm.Select({{$varNameSingular}}AutoIncrementColumns...), qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "item." | join ", "}})).Bind(x)
if err != nil { if err != nil {
t.Errorf("Unable to select insert results with bind: %s", err) t.Errorf("Unable to select insert results with bind: %s", err)
} }

View file

@ -7,7 +7,7 @@ func Test{{$tableNamePlural}}Update(t *testing.T) {
var err error var err error
item := {{$tableNameSingular}}{} item := {{$tableNameSingular}}{}
if err = item.Insert(); err != nil { if err = item.InsertG(); err != nil {
t.Errorf("Unable to insert zero-value item {{$tableNameSingular}}:\n%#v\nErr: %s", item, err) t.Errorf("Unable to insert zero-value item {{$tableNameSingular}}:\n%#v\nErr: %s", item, err)
} }
@ -17,12 +17,12 @@ func Test{{$tableNamePlural}}Update(t *testing.T) {
} }
whitelist := boil.SetComplement({{$varNameSingular}}Columns, {{$varNameSingular}}AutoIncrementColumns) whitelist := boil.SetComplement({{$varNameSingular}}Columns, {{$varNameSingular}}AutoIncrementColumns)
if err = item.Update(whitelist...); err != nil { if err = item.UpdateG(whitelist...); err != nil {
t.Errorf("Unable to update {{$tableNameSingular}}: %s", err) t.Errorf("Unable to update {{$tableNameSingular}}: %s", err)
} }
var j *{{$tableNameSingular}} var j *{{$tableNameSingular}}
j, err = {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "item." | join ", "}}) j, err = {{$tableNameSingular}}FindG({{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "item." | join ", "}})
if err != nil { if err != nil {
t.Errorf("Unable to find {{$tableNameSingular}} row: %s", err) t.Errorf("Unable to find {{$tableNameSingular}} row: %s", err)
} }