sqlboiler/cmds/templates/find.tpl
Patrick O'brien 2f9c936c6a Added inflection library, fixed all templates
* Added inflection to all templates
* Fixed broken template code (for the most part)
2016-03-18 21:26:48 +10:00

17 lines
697 B
Smarty

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