64ec06b4b4
- Use more efficient implementation of the template funcs.
16 lines
689 B
Smarty
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
|
|
}
|