sqlboiler/cmds/templates/findby.tpl
Aaron 64ec06b4b4 Rename some functions.
- Use more efficient implementation of the template funcs.
2016-03-01 08:34:57 -08:00

16 lines
689 B
Smarty

{{- $tableName := .TableName -}}
// {{titleCase $tableName}}FindBy retrieves a single record with the specified column values.
func {{titleCase $tableName}}FindBy(db boil.DB, columns map[string]interface{}) (*{{titleCase $tableName}}, error) {
if id == 0 {
return nil, errors.New("model: no id provided for {{$tableName}} select")
}
{{$varName := camelCase $tableName}}
var {{$varName}} *{{titleCase $tableName}}
err := db.Select(&{{$varName}}, fmt.Sprintf(`SELECT {{selectParamNames $tableName .TableData}} WHERE %s=$1`, column), value)
if err != nil {
return nil, fmt.Errorf("models: unable to select from {{$tableName}}: %s", err)
}
return {{$varName}}, nil
}