2016-03-18 12:26:48 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table -}}
|
|
|
|
// {{$tableNameSingular}}FindSelect retrieves the specified columns for a single record by ID.
|
2016-03-16 15:33:58 +01:00
|
|
|
// Pass in a pointer to an object with `db` tags that match the column names you wish to retrieve.
|
|
|
|
// For example: friendName string `db:"friend_name"`
|
2016-03-18 12:26:48 +01:00
|
|
|
func {{$tableNameSingular}}FindSelect(db boil.DB, id int, results interface{}) error {
|
2016-03-16 15:33:58 +01:00
|
|
|
if id == 0 {
|
2016-03-18 12:26:48 +01:00
|
|
|
return nil, errors.New("{{.PkgName}}: no id provided for {{.Table}} select")
|
2016-03-16 15:33:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
query := fmt.Sprintf(`SELECT %s FROM {{.Table}} WHERE id=$1`, boil.SelectNames(results))
|
2016-03-16 15:33:58 +01:00
|
|
|
err := db.Select(results, query, id)
|
|
|
|
|
|
|
|
if err != nil {
|
2016-03-18 12:26:48 +01:00
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to select from {{.Table}}: %s", err)
|
2016-03-16 15:33:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|