sqlboiler/cmds/templates/find.tpl
Patrick O'brien 270fe59117 Fixed all template function signatures
* Added finisher function signatures
* Added VideoSlice type
* Added videoQuery type
2016-04-17 19:25:09 +10:00

31 lines
1.3 KiB
Smarty

{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $dbName := singular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
// {{$tableNameSingular}}Find retrieves a single record by ID.
func {{$tableNameSingular}}Find(id int64, selectList ...string) (*{{$tableNameSingular}}, error) {
if id == 0 {
return nil, errors.New("{{.PkgName}}: no id provided for {{.Table.Name}} select")
}
var {{$varNameSingular}} *{{$tableNameSingular}}
err := boil.GetDB().Select(&{{$varNameSingular}}, `SELECT {{selectParamNames $dbName .Table.Columns}} WHERE id=$1`, id)
if err != nil {
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", err)
}
return {{$varNameSingular}}, nil
}
func {{$tableNameSingular}}FindX(exec boil.Executor, id int64, selectList ...string) (*{{$tableNameSingular}}, error) {
if id == 0 {
return nil, errors.New("{{.PkgName}}: no id provided for {{.Table.Name}} select")
}
var {{$varNameSingular}} *{{$tableNameSingular}}
err := boil.GetDB().Select(&{{$varNameSingular}}, `SELECT {{selectParamNames $dbName .Table.Columns}} WHERE id=$1`, id)
if err != nil {
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", err)
}
return {{$varNameSingular}}, nil
}