2016-03-18 12:26:48 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table -}}
|
|
|
|
{{- $dbName := singular .Table -}}
|
|
|
|
{{- $tableNamePlural := titleCasePlural .Table -}}
|
|
|
|
{{- $varNamePlural := camelCasePlural .Table -}}
|
|
|
|
// {{$tableNamePlural}}All retrieves all records.
|
|
|
|
func {{$tableNamePlural}}All(db boil.DB) ([]*{{$tableNameSingular}}, error) {
|
|
|
|
var {{$varNamePlural}} []*{{$tableNameSingular}}
|
2016-02-29 12:45:28 +01:00
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
rows, err := db.Query(`SELECT {{selectParamNames $dbName .Columns}} FROM {{.Table}}`)
|
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-17 03:59:56 +01:00
|
|
|
if err := rows.Scan({{scanParamNames $tmpVarName .Columns}}); err != nil {
|
|
|
|
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
|
|
|
}
|