Use extensive piping throughout the templates

- Haskell ftw
This commit is contained in:
Aaron L 2016-06-19 22:22:50 -07:00
parent 5fbcb27f3f
commit 119e683952
19 changed files with 112 additions and 109 deletions

View file

@ -78,6 +78,8 @@ func (s *State) Run(includeTests bool) error {
Tables: s.Tables,
DriverName: s.Config.DriverName,
PkgName: s.Config.PkgName,
StringFuncs: templateStringMappers,
}
if err := generateSingletonOutput(s, singletonData); err != nil {
@ -103,6 +105,8 @@ func (s *State) Run(includeTests bool) error {
Table: table,
DriverName: s.Config.DriverName,
PkgName: s.Config.PkgName,
StringFuncs: templateStringMappers,
}
// Generate the regular templates

View file

@ -125,7 +125,7 @@ func TestColumnNames(t *testing.T) {
}
}
func TestDriverUsesResults(t *testing.T) {
func TestDriverUsesLastInsertID(t *testing.T) {
t.Parallel()
if DriverUsesLastInsertID("postgres") {

View file

@ -1,6 +1,7 @@
package main
import (
"fmt"
"os"
"path/filepath"
"sort"
@ -17,6 +18,8 @@ type templateData struct {
Table dbdrivers.Table
DriverName string
PkgName string
StringFuncs map[string]func(string) string
}
type templateList []*template.Template
@ -80,45 +83,53 @@ func loadTemplate(dir string, filename string) (*template.Template, error) {
return tpl.Lookup(filename), err
}
// templateStringMappers are placed into the data to make it easy to use the
// stringMap function.
var templateStringMappers = map[string]func(string) string{
"singular": strmangle.Singular,
"plural": strmangle.Plural,
// Casing
"toLower": strings.ToLower,
"toUpper": strings.ToUpper,
"titleCase": strmangle.TitleCase,
"camelCase": strmangle.CamelCase,
}
// templateFunctions is a map of all the functions that get passed into the
// templates. If you wish to pass a new function into your own template,
// add a function pointer here.
var templateFunctions = template.FuncMap{
"tolower": strings.ToLower,
"toupper": strings.ToUpper,
"substring": strmangle.Substring,
"singular": strmangle.Singular,
"plural": strmangle.Plural,
"titleCase": strmangle.TitleCase,
"titleCaseSingular": strmangle.TitleCaseSingular,
"titleCasePlural": strmangle.TitleCasePlural,
"titleCaseCommaList": strmangle.TitleCaseCommaList,
"camelCase": strmangle.CamelCase,
"camelCaseSingular": strmangle.CamelCaseSingular,
"camelCasePlural": strmangle.CamelCasePlural,
"camelCaseCommaList": strmangle.CamelCaseCommaList,
"columnsToStrings": strmangle.ColumnsToStrings,
"commaList": strmangle.CommaList,
"makeDBName": strmangle.MakeDBName,
"selectParamNames": strmangle.SelectParamNames,
"insertParamNames": strmangle.InsertParamNames,
"insertParamFlags": strmangle.InsertParamFlags,
"insertParamVariables": strmangle.InsertParamVariables,
"scanParamNames": strmangle.ScanParamNames,
"hasPrimaryKey": strmangle.HasPrimaryKey,
"primaryKeyFuncSig": strmangle.PrimaryKeyFuncSig,
"wherePrimaryKey": strmangle.WherePrimaryKey,
"paramsPrimaryKey": strmangle.ParamsPrimaryKey,
"primaryKeyFlagIndex": strmangle.PrimaryKeyFlagIndex,
"updateParamNames": strmangle.UpdateParamNames,
"updateParamVariables": strmangle.UpdateParamVariables,
"supportsResultObject": strmangle.SupportsResultObject,
// String ops
"substring": strmangle.Substring,
"remove": func(rem string, str string) string { return strings.Replace(str, rem, "", -1) },
"prefix": func(add string, str string) string { return fmt.Sprintf("%s%s", add, str) },
// Pluralization
"singular": strmangle.Singular,
"plural": strmangle.Plural,
// Casing
"toLower": strings.ToLower,
"toUpper": strings.ToUpper,
"titleCase": strmangle.TitleCase,
"camelCase": strmangle.CamelCase,
// String Slice ops
"join": func(sep string, slice []string) string { return strings.Join(slice, sep) },
"stringMap": strmangle.StringMap,
"hasElement": strmangle.HasElement,
"prefixStringSlice": strmangle.PrefixStringSlice,
// Database related mangling
"wherePrimaryKey": strmangle.WherePrimaryKey,
// dbdrivers ops
"driverUsesLastInsertID": strmangle.DriverUsesLastInsertID,
"filterColumnsByDefault": strmangle.FilterColumnsByDefault,
"filterColumnsByAutoIncrement": strmangle.FilterColumnsByAutoIncrement,
"autoIncPrimaryKey": strmangle.AutoIncPrimaryKey,
"addID": strmangle.AddID,
"removeID": strmangle.RemoveID,
"randDBStruct": strmangle.RandDBStruct,
"randDBStructSlice": strmangle.RandDBStructSlice,
"primaryKeyFuncSig": strmangle.PrimaryKeyFuncSig,
"columnNames": strmangle.ColumnNames,
"makeDBName": strmangle.MakeDBName,
}

View file

@ -1,4 +1,4 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
// {{$tableNameSingular}} is an object representing the database table.
type {{$tableNameSingular}} struct {

View file

@ -1,10 +1,10 @@
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
var (
{{$varNameSingular}}Columns = []string{{"{"}}{{columnsToStrings .Table.Columns | commaList}}{{"}"}}
{{$varNameSingular}}Columns = []string{{"{"}}{{.Table.Columns | columnNames | join ", "}}{{"}"}}
{{$varNameSingular}}ColumnsWithoutDefault = []string{{"{"}}{{filterColumnsByDefault .Table.Columns false}}{{"}"}}
{{$varNameSingular}}ColumnsWithDefault = []string{{"{"}}{{filterColumnsByDefault .Table.Columns true}}{{"}"}}
{{$varNameSingular}}PrimaryKeyColumns = []string{{"{"}}{{commaList .Table.PKey.Columns}}{{"}"}}
{{$varNameSingular}}PrimaryKeyColumns = []string{{"{"}}{{.Table.PKey.Columns | join ", "}}{{"}"}}
{{$varNameSingular}}AutoIncrementColumns = []string{{"{"}}{{filterColumnsByAutoIncrement .Table.Columns}}{{"}"}}
{{$varNameSingular}}AutoIncPrimaryKey = "{{autoIncPrimaryKey .Table.Columns .Table.PKey}}"
)

View file

@ -1,5 +1,5 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
var {{$varNameSingular}}BeforeCreateHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}BeforeUpdateHooks []{{$tableNameSingular}}Hook
var {{$varNameSingular}}AfterCreateHooks []{{$tableNameSingular}}Hook

View file

@ -1,5 +1,5 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
// One returns a single {{$varNameSingular}} record from the query.
func (q {{$varNameSingular}}Query) One() (*{{$tableNameSingular}}, error) {
o := &{{$tableNameSingular}}{}

View file

@ -1,13 +1,13 @@
{{- if .Table.IsJoinTable -}}
{{- else -}}
{{- $pkg := .PkgName -}}
{{- $localTable := titleCaseSingular .Table.Name -}}
{{- $localTable := .Table.Name | singular | titleCase -}}
{{- range .Table.FKeys -}}
{{- $localColumn := .Column | removeID | titleCaseSingular -}}
{{- $foreignColumn := .Column | removeID | titleCaseSingular -}}
{{- $foreignTable := titleCaseSingular .ForeignTable -}}
{{- $varname := camelCaseSingular .ForeignTable -}}
{{- $receiver := $localTable | tolower | substring 0 1 -}}
{{- $localColumn := .Column | remove "_id" | singular | titleCase -}}
{{- $foreignColumn := .Column | remove "_id" | singular | titleCase -}}
{{- $foreignTable := .ForeignTable | singular | titleCase -}}
{{- $varname := .ForeignTable | singular | camelCase -}}
{{- $receiver := $localTable | toLower | substring 0 1 -}}
// {{$foreignColumn}} fetches the {{$foreignTable}} pointed to by the foreign key.
func ({{$receiver}} *{{$localTable}}) {{$foreignColumn}}(exec boil.Executor, selectCols ...string) (*{{$foreignTable}}, error) {
{{$varname}} := &{{$foreignTable}}{}

View file

@ -1,6 +1,6 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
// {{$tableNamePlural}}All retrieves all records.
func {{$tableNamePlural}}(mods ...qm.QueryMod) {{$varNameSingular}}Query {
return {{$tableNamePlural}}X(boil.GetDB(), mods...)

View file

@ -1,10 +1,9 @@
{{- if hasPrimaryKey .Table.PKey -}}
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
// {{$tableNameSingular}}Find retrieves a single record by ID.
func {{$tableNameSingular}}Find({{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
return {{$tableNameSingular}}FindX(boil.GetDB(), {{camelCaseCommaList "" .Table.PKey.Columns}}, selectCols...)
return {{$tableNameSingular}}FindX(boil.GetDB(), {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | join ", "}}, selectCols...)
}
func {{$tableNameSingular}}FindX(exec boil.Executor, {{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
@ -13,7 +12,7 @@ func {{$tableNameSingular}}FindX(exec boil.Executor, {{primaryKeyFuncSig .Table.
mods := []qm.QueryMod{
qm.Select(selectCols...),
qm.Table("{{.Table.Name}}"),
qm.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{camelCaseCommaList "" .Table.PKey.Columns}}),
qm.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | join ", "}}),
}
q := NewQueryX(exec, mods...)
@ -26,4 +25,3 @@ func {{$tableNameSingular}}FindX(exec boil.Executor, {{primaryKeyFuncSig .Table.
return {{$varNameSingular}}, nil
}
{{- end -}}

View file

@ -1,6 +1,5 @@
{{- if hasPrimaryKey .Table.PKey -}}
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
// {{$tableNameSingular}}Insert inserts a single record.
func (o *{{$tableNameSingular}}) Insert(whitelist ... string) error {
return o.InsertX(boil.GetDB(), whitelist...)
@ -31,7 +30,7 @@ func (o *{{$tableNameSingular}}) InsertX(exec boil.Executor, whitelist ... strin
ins := fmt.Sprintf(`INSERT INTO {{.Table.Name}} (%s) VALUES (%s)`, strings.Join(wl, ","), boil.GenerateParamFlags(len(wl), 1))
{{if supportsResultObject .DriverName}}
{{if driverUsesLastInsertID .DriverName}}
if len(returnColumns) != 0 {
result, err := exec.Exec(ins, boil.GetStructValues(o, wl...)...)
if err != nil {
@ -66,7 +65,7 @@ func (o *{{$tableNameSingular}}) InsertX(exec boil.Executor, whitelist ... strin
ins = ins + fmt.Sprintf(` RETURNING %s`, strings.Join(returnColumns, ","))
err = exec.QueryRow(ins, boil.GetStructValues(o, wl...)...).Scan(boil.GetStructPointers(o, returnColumns...)...)
} else {
_, err = exec.Exec(ins, {{insertParamVariables "o." .Table.Columns}})
_, err = exec.Exec(ins, {{.Table.Columns | columnNames | prefixStringSlice "o." | join ", "}})
}
{{end}}
@ -84,4 +83,3 @@ func (o *{{$tableNameSingular}}) InsertX(exec boil.Executor, whitelist ... strin
return nil
}
{{- end -}}

View file

@ -1,6 +1,5 @@
{{if hasPrimaryKey .Table.PKey -}}
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
// Update a single {{$tableNameSingular}} record. It takes a whitelist of
// column_name's that should be updated. The primary key will be used to find
// the record to update.
@ -11,11 +10,11 @@ func (o *{{$tableNameSingular}}) Update(whitelist ... string) error {
}
func (o *{{$tableNameSingular}}) UpdateX(exec boil.Executor, whitelist ... string) error {
return o.UpdateAtX(exec, {{titleCaseCommaList "o." .Table.PKey.Columns}}, whitelist...)
return o.UpdateAtX(exec, {{.Table.PKey.Columns | prefixStringSlice "o." | stringMap .StringFuncs.titleCase | join ", "}}, whitelist...)
}
func (o *{{$tableNameSingular}}) UpdateAt({{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, whitelist ...string) error {
return o.UpdateAtX(boil.GetDB(), {{camelCaseCommaList "" .Table.PKey.Columns}}, whitelist...)
return o.UpdateAtX(boil.GetDB(), {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | join ", "}}, whitelist...)
}
func (o *{{$tableNameSingular}}) UpdateAtX(exec boil.Executor, {{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, whitelist ...string) error {
@ -37,8 +36,8 @@ func (o *{{$tableNameSingular}}) UpdateAtX(exec boil.Executor, {{primaryKeyFuncS
var err error
var query string
if len(whitelist) != 0 {
query = fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, boil.SetParamNames(whitelist), boil.WherePrimaryKey(len(whitelist)+1, {{commaList .Table.PKey.Columns}}))
_, err = exec.Exec(query, boil.GetStructValues(o, whitelist...), {{paramsPrimaryKey "o." .Table.PKey.Columns true}})
query = fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, boil.SetParamNames(whitelist), boil.WherePrimaryKey(len(whitelist)+1, {{.Table.PKey.Columns | join ", "}}))
_, err = exec.Exec(query, boil.GetStructValues(o, whitelist...), {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | prefixStringSlice "o." | join ", "}})
} else {
return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}}, could not build a whitelist for row: %s", err)
}
@ -68,4 +67,3 @@ func (q {{$varNameSingular}}Query) UpdateAll(cols M) error {
return nil
}
{{- end}}

View file

@ -1,6 +1,5 @@
{{if hasPrimaryKey .Table.PKey -}}
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
// Delete deletes a single {{$tableNameSingular}} record.
// Delete will match against the primary key column to find the record to delete.
func (o *{{$tableNameSingular}}) Delete() error {
@ -20,7 +19,7 @@ func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error {
mods = append(mods,
qm.Table("{{.Table.Name}}"),
qm.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{paramsPrimaryKey "o." .Table.PKey.Columns true}}),
qm.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | prefixStringSlice "o." | join ", "}}),
)
query := NewQueryX(exec, mods...)
@ -64,7 +63,7 @@ func (o {{$varNameSingular}}Slice) DeleteAllX(exec boil.Executor) error {
var mods []qm.QueryMod
args := o.inPrimaryKeyArgs()
in := boil.WherePrimaryKeyIn(len(o), {{commaList .Table.PKey.Columns}})
in := boil.WherePrimaryKeyIn(len(o), {{.Table.PKey.Columns | join ", "}})
mods = append(mods,
qm.Table("{{.Table.Name}}"),
@ -84,4 +83,3 @@ func (o {{$varNameSingular}}Slice) DeleteAllX(exec boil.Executor) error {
return nil
}
{{- end}}

View file

@ -1,6 +1,5 @@
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- if hasPrimaryKey .Table.PKey -}}
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
func (o {{$tableNameSingular}}) inPrimaryKeyArgs() []interface{} {
var args []interface{}
@ -22,4 +21,3 @@ func (o {{$varNameSingular}}Slice) inPrimaryKeyArgs() []interface{} {
return args
}
{{- end}}

View file

@ -1,8 +1,8 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNamePlural := camelCasePlural .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func {{$varNameSingular}}CompareVals(o *{{$tableNameSingular}}, j *{{$tableNameSingular}}, t *testing.T) {
{{range $key, $value := .Table.Columns}}
{{if eq $value.Type "null.Time"}}

View file

@ -1,8 +1,8 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNamePlural := camelCasePlural .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func {{$varNamePlural}}DeleteAllRows(t *testing.T) {
// Delete all rows to give a clean slate
err := {{$tableNamePlural}}().DeleteAll()

View file

@ -1,8 +1,8 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNamePlural := camelCasePlural .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func Test{{$tableNamePlural}}Find(t *testing.T) {
var err error
@ -22,17 +22,15 @@ func Test{{$tableNamePlural}}Find(t *testing.T) {
j := make({{$varNameSingular}}Slice, 3)
// Perform all Find queries and assign result objects to slice for comparison
for i := 0; i < len(j); i++ {
j[i], err = {{$tableNameSingular}}Find({{titleCaseCommaList "o[i]." .Table.PKey.Columns}})
j[i], err = {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | prefixStringSlice "o[i]." | join ", "}})
{{$varNameSingular}}CompareVals(o[i], j[i], t)
}
{{if hasPrimaryKey .Table.PKey}}
f, err := {{$tableNameSingular}}Find({{titleCaseCommaList "o[0]." .Table.PKey.Columns}}, {{$varNameSingular}}PrimaryKeyColumns...)
f, err := {{$tableNameSingular}}Find({{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | prefixStringSlice "o[0]." | join ", "}}, {{$varNameSingular}}PrimaryKeyColumns...)
{{range $key, $value := .Table.PKey.Columns}}
if o[0].{{titleCase $value}} != f.{{titleCase $value}} {
t.Errorf("Expected primary key values to match, {{titleCase $value}} did not match")
}
{{end}}
colsWithoutPrimKeys := boil.SetComplement({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns)
fRef := reflect.ValueOf(f).Elem()

View file

@ -1,8 +1,8 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNamePlural := camelCasePlural .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func Test{{$tableNamePlural}}Bind(t *testing.T) {
var err error
@ -19,7 +19,7 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
j := {{$tableNameSingular}}{}
err = {{$tableNamePlural}}(qm.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{titleCaseCommaList "o." .Table.PKey.Columns}})).Bind(&j)
err = {{$tableNamePlural}}(qm.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{.Table.PKey.Columns | stringMap .StringFuncs.camelCase | prefixStringSlice "o." | join ", "}})).Bind(&j)
if err != nil {
t.Errorf("Unable to call Bind on {{$tableNameSingular}} single object: %s", err)
}
@ -47,7 +47,7 @@ func Test{{$tableNamePlural}}Bind(t *testing.T) {
if err != nil {
t.Errorf("Unable to call Bind on {{$tableNameSingular}} slice of objects: %s", err)
}
if len(k) != 3 {
t.Errorf("Expected 3 results, got %d", len(k))
}

View file

@ -1,8 +1,8 @@
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $dbName := singular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNamePlural := camelCasePlural .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
func Test{{$tableNamePlural}}InPrimaryKeyArgs(t *testing.T) {
var err error
var o {{$tableNameSingular}}