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 {
|
|
|
|
return nil, errors.New("model: no id provided for {{$tableName}} select")
|
|
|
|
}
|
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 {
|
|
|
|
return nil, fmt.Errorf("models: unable to select from {{$tableName}}: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {{$varName}}, nil
|
|
|
|
}
|