2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
|
|
|
{{- $dbName := singular .Table.Name -}}
|
|
|
|
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$tableNameSingular}}Find retrieves a single record by ID.
|
|
|
|
func {{$tableNameSingular}}Find(db boil.DB, id int) (*{{$tableNameSingular}}, error) {
|
2016-02-29 12:45:28 +01:00
|
|
|
if id == 0 {
|
2016-03-23 07:18:41 +01:00
|
|
|
return nil, errors.New("{{.PkgName}}: no id provided for {{.Table.Name}} select")
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
2016-03-18 12:26:48 +01:00
|
|
|
var {{$varNameSingular}} *{{$tableNameSingular}}
|
2016-03-23 07:18:41 +01:00
|
|
|
err := db.Select(&{{$varNameSingular}}, `SELECT {{selectParamNames $dbName .Table.Columns}} WHERE id=$1`, id)
|
2016-02-29 12:45:28 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-03-23 07:18:41 +01:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", err)
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
return {{$varNameSingular}}, nil
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|