* Added bunch of new command names and descriptions. * Changed "all" command to "boil", so we can use "all" for the name of the all database select helper.
19 lines
904 B
Smarty
19 lines
904 B
Smarty
{{- $tableName := .TableName -}}
|
|
// {{makeGoColName $tableName}}FieldsFindBy retrieves the specified columns
|
|
// for a single record with the specified column values.
|
|
// 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"`
|
|
func {{makeGoColName $tableName}}FieldsFindBy(db *sqlx.DB, columns map[string]interface{}, results interface{}) (*{{makeGoColName $tableName}}, error) {
|
|
if id == 0 {
|
|
return nil, errors.New("model: no id provided for {{$tableName}} select")
|
|
}
|
|
{{$varName := makeGoVarName $tableName}}
|
|
var {{$varName}} *{{makeGoColName $tableName}}
|
|
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
|
|
}
|