2016-03-02 05:05:25 +01:00
|
|
|
{{- $tableName := titleCase .Table -}}
|
|
|
|
{{- $varName := camelCase $tableName -}}
|
|
|
|
// {{$tableName}}All retrieves all records.
|
|
|
|
func {{$tableName}}All(db boil.DB) ([]*{{$tableName}}, error) {
|
|
|
|
var {{$varName}} []*{{$tableName}}
|
2016-02-29 12:45:28 +01:00
|
|
|
|
2016-03-02 05:05:25 +01:00
|
|
|
rows, err := db.Query(`SELECT {{selectParamNames .Table .Columns}}`)
|
2016-02-29 12:45:28 +01:00
|
|
|
if err != nil {
|
2016-03-02 05:05:25 +01:00
|
|
|
return nil, fmt.Errorf("models: failed to query: %v", err)
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
|
|
|
|
2016-03-02 05:05:25 +01:00
|
|
|
for rows.Next() {
|
|
|
|
{{$varName}}Tmp := {{$tableName}}{}
|
|
|
|
|
|
|
|
if err := rows.Scan({{scanParamNames $varName .Columns}}); err != nil {
|
|
|
|
return nil, fmt.Errorf("models: failed to scan row: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
{{$varName}} = append({{$varName}}, {{$varName}}Tmp)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, fmt.Errorf("models: failed to read rows: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {{$varName}}, nil
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|