2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
|
|
|
{{- $dbName := singular .Table.Name -}}
|
|
|
|
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
|
|
|
|
{{- $varNamePlural := camelCasePlural .Table.Name -}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$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))
|
2016-03-18 12:26:48 +01:00
|
|
|
err := db.Select(&{{$varNamePlural}}, query, boil.WhereParams(columns)...)
|
2016-03-16 15:33:58 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-03-23 07:18:41 +01:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", err)
|
2016-03-16 15:33:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
return {{$varNamePlural}}, nil
|
2016-03-16 15:33:58 +01:00
|
|
|
}
|