2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-09 12:19:42 +02:00
|
|
|
// OneP returns a single {{$varNameSingular}} record from the query, and panics on error.
|
|
|
|
func (q {{$varNameSingular}}Query) OneP() (*{{$tableNameSingular}}) {
|
|
|
|
o, err := q.One()
|
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return o
|
|
|
|
}
|
|
|
|
|
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-08-08 08:07:15 +02:00
|
|
|
err := q.Bind(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-08-09 12:19:42 +02:00
|
|
|
// AllP returns all {{$tableNameSingular}} records from the query, and panics on error.
|
|
|
|
func (q {{$varNameSingular}}Query) AllP() {{$tableNameSingular}}Slice {
|
|
|
|
o, err := q.All()
|
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-07-16 13:22:57 +02:00
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
return o
|
2016-07-16 13:22:57 +02:00
|
|
|
}
|
|
|
|
|
2016-06-20 01:29:59 +02:00
|
|
|
// All returns all {{$tableNameSingular}} records from the query.
|
2016-07-16 16:15:14 +02:00
|
|
|
func (q {{$varNameSingular}}Query) All() ({{$tableNameSingular}}Slice, error) {
|
|
|
|
var o {{$tableNameSingular}}Slice
|
2016-05-10 12:20:29 +02:00
|
|
|
|
2016-08-08 08:07:15 +02:00
|
|
|
err := q.Bind(&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-08-09 12:19:42 +02:00
|
|
|
// CountP returns the count of all {{$tableNameSingular}} records in the query, and panics on error.
|
|
|
|
func (q {{$varNameSingular}}Query) CountP() int64 {
|
|
|
|
c, err := q.Count()
|
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-07-16 13:22:57 +02:00
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
return c
|
2016-07-16 13:22:57 +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
|
|
|
}
|
2016-07-16 13:22:57 +02:00
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
// Exists checks if the row exists in the table, and panics on error.
|
|
|
|
func (q {{$varNameSingular}}Query) ExistsP() bool {
|
|
|
|
e, err := q.Exists()
|
2016-07-16 13:22:57 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
return e
|
2016-07-16 13:22:57 +02:00
|
|
|
}
|
2016-08-03 12:23:43 +02:00
|
|
|
|
|
|
|
// Exists checks if the row exists in the table.
|
|
|
|
func (q {{$varNameSingular}}Query) Exists() (bool, error) {
|
|
|
|
var count int64
|
|
|
|
|
|
|
|
boil.SetCount(q.Query)
|
|
|
|
boil.SetLimit(q.Query, 1)
|
|
|
|
|
|
|
|
err := boil.ExecQueryOne(q.Query).Scan(&count)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("{{.PkgName}}: failed to check if {{.Table.Name}} exists: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return count > 0, nil
|
|
|
|
}
|