sqlboiler/cmds/templates/where.tpl
Patrick O'brien 2f9c936c6a Added inflection library, fixed all templates
* Added inflection to all templates
* Fixed broken template code (for the most part)
2016-03-18 21:26:48 +10:00

17 lines
777 B
Smarty

{{- $tableNameSingular := titleCaseSingular .Table -}}
{{- $dbName := singular .Table -}}
{{- $tableNamePlural := titleCasePlural .Table -}}
{{- $varNamePlural := camelCasePlural .Table -}}
// {{$tableNamePlural}}Where retrieves all records with the specified column values.
func {{$tableNamePlural}}Where(db boil.DB, columns map[string]interface{}) ([]*{{$tableNameSingular}}, error) {
var {{$varNamePlural}} []*{{$tableNameSingular}}
query := fmt.Sprintf(`SELECT {{selectParamNames $dbName .Columns}} FROM {{.Table}} WHERE %s`, boil.Where(columns))
err := db.Select(&{{$varNamePlural}}, query, boil.WhereParams(columns)...)
if err != nil {
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table}}: %s", err)
}
return {{$varNamePlural}}, nil
}