sqlboiler/cmds/templates/all.tpl

41 lines
1.3 KiB
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 -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
2016-03-23 07:18:41 +01:00
{{- $varNamePlural := camelCasePlural .Table.Name -}}
type {{$varNameSingular}}Query struct {
*boil.Query
}
// {{$tableNamePlural}}All retrieves all records.
func {{$tableNamePlural}}(mods ...QueryMod) {{$varNameSingular}}Query {
var {{$varNamePlural}} []*{{$tableNameSingular}}
rows, err := boil.GetDB().Query(`SELECT {{selectParamNames $dbName .Table.Columns}} FROM {{.Table.Name}}`)
if err != nil {
return nil, fmt.Errorf("{{.PkgName}}: failed to query: %v", err)
}
2016-03-17 03:59:56 +01:00
for rows.Next() {
{{- $tmpVarName := (print $varNamePlural "Tmp") -}}
{{$varNamePlural}}Tmp := {{$tableNameSingular}}{}
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)
}
{{$varNamePlural}} = append({{$varNamePlural}}, &{{$varNamePlural}}Tmp)
2016-03-17 03:59:56 +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)
}
return {{$varNamePlural}}, nil
}
func {{$tableNamePlural}}X(exec boil.Executor, mods ...QueryMod) {{$tableNameSingular}}Query {
}