sqlboiler/cmds/templates/where.tpl

17 lines
813 B
Smarty
Raw Normal View History

2016-03-23 07:18:41 +01:00
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $dbName := singular .Table.Name -}}
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
{{- $varNamePlural := camelCasePlural .Table.Name -}}
// {{$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}}
2016-03-23 07:18:41 +01:00
query := fmt.Sprintf(`SELECT {{selectParamNames $dbName .Table.Columns}} FROM {{.Table.Name}} WHERE %s`, boil.Where(columns))
err := db.Select(&{{$varNamePlural}}, query, boil.WhereParams(columns)...)
if err != nil {
2016-03-23 07:18:41 +01:00
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", err)
}
return {{$varNamePlural}}, nil
}