2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
|
|
|
{{- $dbName := singular .Table.Name -}}
|
|
|
|
{{- $tableNamePlural := titleCasePlural .Table.Name -}}
|
2016-04-17 11:25:09 +02:00
|
|
|
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
|
2016-03-23 07:18:41 +01:00
|
|
|
{{- $varNamePlural := camelCasePlural .Table.Name -}}
|
2016-04-17 11:25:09 +02:00
|
|
|
type {{$varNameSingular}}Query struct {
|
|
|
|
*boil.Query
|
|
|
|
}
|
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$tableNamePlural}}All retrieves all records.
|
2016-04-17 11:25:09 +02:00
|
|
|
func {{$tableNamePlural}}(mods ...QueryMod) {{$varNameSingular}}Query {
|
2016-03-18 12:26:48 +01:00
|
|
|
var {{$varNamePlural}} []*{{$tableNameSingular}}
|
2016-02-29 12:45:28 +01:00
|
|
|
|
2016-04-13 15:51:58 +02:00
|
|
|
rows, err := boil.GetDB().Query(`SELECT {{selectParamNames $dbName .Table.Columns}} FROM {{.Table.Name}}`)
|
2016-02-29 12:45:28 +01:00
|
|
|
if err != nil {
|
2016-03-16 15:33:58 +01:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: failed to query: %v", err)
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
|
|
|
|
2016-03-17 03:59:56 +01:00
|
|
|
for rows.Next() {
|
2016-03-18 12:26:48 +01:00
|
|
|
{{- $tmpVarName := (print $varNamePlural "Tmp") -}}
|
|
|
|
{{$varNamePlural}}Tmp := {{$tableNameSingular}}{}
|
2016-03-02 05:05:25 +01:00
|
|
|
|
2016-03-23 07:18:41 +01:00
|
|
|
if err := rows.Scan({{scanParamNames $tmpVarName .Table.Columns}}); err != nil {
|
2016-03-17 03:59:56 +01:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: failed to scan row: %v", err)
|
|
|
|
}
|
2016-03-02 05:05:25 +01:00
|
|
|
|
2016-03-23 04:03:35 +01:00
|
|
|
{{$varNamePlural}} = append({{$varNamePlural}}, &{{$varNamePlural}}Tmp)
|
2016-03-17 03:59:56 +01:00
|
|
|
}
|
2016-03-02 05:05:25 +01:00
|
|
|
|
2016-03-17 03:59:56 +01:00
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: failed to read rows: %v", err)
|
|
|
|
}
|
2016-03-02 05:05:25 +01:00
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
return {{$varNamePlural}}, nil
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
2016-04-17 11:25:09 +02:00
|
|
|
|
|
|
|
func {{$tableNamePlural}}X(exec boil.Executor, mods ...QueryMod) {{$tableNameSingular}}Query {
|
|
|
|
|
|
|
|
|
|
|
|
}
|