2016-02-29 12:45:28 +01:00
|
|
|
{{- $tableName := .TableName -}}
|
2016-03-01 16:53:56 +01:00
|
|
|
// {{makeGoName $tableName}}Find retrieves a single record by ID.
|
|
|
|
func {{makeGoName $tableName}}Find(db boil.DB, id int) (*{{makeGoName $tableName}}, error) {
|
2016-02-29 12:45:28 +01:00
|
|
|
if id == 0 {
|
|
|
|
return nil, errors.New("model: no id provided for {{$tableName}} select")
|
|
|
|
}
|
|
|
|
{{$varName := makeGoVarName $tableName}}
|
2016-03-01 16:53:56 +01:00
|
|
|
var {{$varName}} *{{makeGoName $tableName}}
|
2016-02-29 12:45:28 +01:00
|
|
|
err := db.Select(&{{$varName}}, `SELECT {{makeSelectParamNames $tableName .TableData}} WHERE id=$1`, id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("models: unable to select from {{$tableName}}: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {{$varName}}, nil
|
|
|
|
}
|