Use the new bind in all templates
This commit is contained in:
parent
989bece6b3
commit
444153222b
3 changed files with 10 additions and 23 deletions
|
@ -6,8 +6,7 @@ func (q {{$varNameSingular}}Query) One() (*{{$tableNameSingular}}, error) {
|
|||
|
||||
boil.SetLimit(q.Query, 1)
|
||||
|
||||
res := boil.ExecQueryOne(q.Query)
|
||||
err := boil.BindOne(res, boil.Select(q.Query), o)
|
||||
err := q.Bind(o)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("{{.PkgName}}: failed to execute a one query for {{.Table.Name}}: %s", err)
|
||||
}
|
||||
|
@ -29,13 +28,7 @@ func (q {{$varNameSingular}}Query) OneP() (*{{$tableNameSingular}}) {
|
|||
func (q {{$varNameSingular}}Query) All() ({{$tableNameSingular}}Slice, error) {
|
||||
var o {{$tableNameSingular}}Slice
|
||||
|
||||
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)
|
||||
}
|
||||
defer res.Close()
|
||||
|
||||
err = boil.BindAll(res, boil.Select(q.Query), &o)
|
||||
err := q.Bind(&o)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("{{.PkgName}}: failed to assign all query results to {{$tableNameSingular}} slice: %s", err)
|
||||
}
|
||||
|
|
|
@ -32,8 +32,7 @@ func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...s
|
|||
|
||||
q := NewQuery(exec, mods...)
|
||||
|
||||
err := boil.ExecQueryOne(q).Scan(boil.GetStructPointers({{$varNameSingular}}, selectCols...)...)
|
||||
|
||||
err := q.Bind({{$varNameSingular}})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %v", err)
|
||||
}
|
||||
|
|
|
@ -4,24 +4,19 @@
|
|||
{{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}}
|
||||
// {{$tableNameSingular}}Exists checks if the {{$tableNameSingular}} row exists.
|
||||
func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error) {
|
||||
var count int64
|
||||
var exists bool
|
||||
|
||||
mods := []qm.QueryMod{
|
||||
qm.From("{{.Table.Name}}"),
|
||||
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{$pkNames | join ", "}}),
|
||||
qm.Limit(1),
|
||||
}
|
||||
row := exec.QueryRow(
|
||||
`select exists(select 1 from "{{.Table.Name}}" where {{whereClause .Table.PKey.Columns (len $pkNames)}} limit 1)`,
|
||||
{{$pkNames | join ", "}},
|
||||
)
|
||||
|
||||
q := NewQuery(exec, mods...)
|
||||
|
||||
boil.SetCount(q)
|
||||
|
||||
err := boil.ExecQueryOne(q).Scan(&count)
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("{{.PkgName}}: unable to check if {{.Table.Name}} exists: %v", err)
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// {{$tableNameSingular}}ExistsG checks if the {{$tableNameSingular}} row exists.
|
||||
|
|
Loading…
Add table
Reference in a new issue