2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$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-23 07:18:41 +01:00
|
|
|
return errors.New("{{.PkgName}}: no id provided for {{.Table.Name}} select")
|
2016-03-16 15:33:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 07:18:41 +01:00
|
|
|
query := fmt.Sprintf(`SELECT %s FROM {{.Table.Name}} 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-23 07:18:41 +01:00
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", err)
|
2016-03-16 15:33:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|