2016-03-02 05:05:25 +01:00
|
|
|
{{- $tableName := .Table -}}
|
2016-03-01 17:34:57 +01:00
|
|
|
// {{titleCase $tableName}}Find retrieves a single record by ID.
|
|
|
|
func {{titleCase $tableName}}Find(db boil.DB, id int) (*{{titleCase $tableName}}, error) {
|
2016-02-29 12:45:28 +01:00
|
|
|
if id == 0 {
|
2016-03-16 15:33:58 +01:00
|
|
|
return nil, errors.New("{{.PkgName}}: no id provided for {{$tableName}} select")
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
2016-03-01 17:34:57 +01:00
|
|
|
{{$varName := camelCase $tableName}}
|
|
|
|
var {{$varName}} *{{titleCase $tableName}}
|
2016-03-02 05:05:25 +01:00
|
|
|
err := db.Select(&{{$varName}}, `SELECT {{selectParamNames $tableName .Columns}} WHERE id=$1`, id)
|
2016-02-29 12:45:28 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-03-16 15:33:58 +01:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{$tableName}}: %s", err)
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return {{$varName}}, nil
|
|
|
|
}
|