2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-06-20 01:29:59 +02:00
|
|
|
// One returns a single {{$varNameSingular}} record from the query.
|
2016-05-03 15:42:25 +02:00
|
|
|
func (q {{$varNameSingular}}Query) One() (*{{$tableNameSingular}}, error) {
|
2016-06-10 16:22:08 +02:00
|
|
|
o := &{{$tableNameSingular}}{}
|
2016-05-03 15:42:25 +02:00
|
|
|
|
2016-05-10 12:20:29 +02:00
|
|
|
boil.SetLimit(q.Query, 1)
|
2016-05-03 15:42:25 +02:00
|
|
|
|
2016-05-10 12:20:29 +02:00
|
|
|
res := boil.ExecQueryOne(q.Query)
|
2016-06-07 06:38:17 +02:00
|
|
|
err := boil.BindOne(res, boil.Select(q.Query), o)
|
2016-05-10 12:20:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: failed to execute a one query for {{.Table.Name}}: %s", err)
|
|
|
|
}
|
2016-05-03 15:42:25 +02:00
|
|
|
|
2016-05-10 12:20:29 +02:00
|
|
|
return o, nil
|
2016-04-17 11:25:09 +02:00
|
|
|
}
|
|
|
|
|
2016-06-20 01:29:59 +02:00
|
|
|
// All returns all {{$tableNameSingular}} records from the query.
|
2016-05-03 15:42:25 +02:00
|
|
|
func (q {{$varNameSingular}}Query) All() ({{$varNameSingular}}Slice, error) {
|
2016-06-07 06:38:17 +02:00
|
|
|
var o {{$varNameSingular}}Slice
|
2016-05-10 12:20:29 +02:00
|
|
|
|
|
|
|
res, err := boil.ExecQueryAll(q.Query)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: failed to execute an all query for {{.Table.Name}}: %s", err)
|
|
|
|
}
|
2016-06-08 07:45:34 +02:00
|
|
|
defer res.Close()
|
2016-05-10 12:20:29 +02:00
|
|
|
|
2016-06-07 06:38:17 +02:00
|
|
|
err = boil.BindAll(res, boil.Select(q.Query), &o)
|
2016-05-10 12:20:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: failed to assign all query results to {{$tableNameSingular}} slice: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
2016-04-17 11:25:09 +02:00
|
|
|
}
|
|
|
|
|
2016-06-20 01:29:59 +02:00
|
|
|
// Count returns the count of all {{$tableNameSingular}} records in the query.
|
2016-05-03 15:42:25 +02:00
|
|
|
func (q {{$varNameSingular}}Query) Count() (int64, error) {
|
2016-05-10 12:20:29 +02:00
|
|
|
var count int64
|
|
|
|
|
|
|
|
boil.SetCount(q.Query)
|
|
|
|
|
|
|
|
err := boil.ExecQueryOne(q.Query).Scan(&count)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("{{.PkgName}}: failed to count {{.Table.Name}} rows: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return count, nil
|
2016-04-17 11:25:09 +02:00
|
|
|
}
|