2016-06-19 22:22:50 -07:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
2016-03-22 23:18:41 -07:00
|
|
|
{{- $dbName := singular .Table.Name -}}
|
2016-06-19 22:22:50 -07:00
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-06-26 23:56:05 -07:00
|
|
|
{{- $colDefs := sqlColDefinitions .Table.Columns .Table.PKey.Columns -}}
|
|
|
|
{{- $pkNames := $colDefs.Names | stringMap .StringFuncs.camelCase -}}
|
|
|
|
{{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}}
|
2016-08-01 15:10:10 +10:00
|
|
|
// {{$tableNameSingular}}FindG retrieves a single record by ID.
|
|
|
|
func {{$tableNameSingular}}FindG({{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
|
|
|
return {{$tableNameSingular}}Find(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...)
|
2016-04-24 15:33:05 +10:00
|
|
|
}
|
|
|
|
|
2016-08-01 15:10:10 +10:00
|
|
|
// {{$tableNameSingular}}FindGP retrieves a single record by ID, and panics on error.
|
|
|
|
func {{$tableNameSingular}}FindGP({{$pkArgs}}, selectCols ...string) *{{$tableNameSingular}} {
|
2016-08-05 15:03:37 +10:00
|
|
|
retobj, err := {{$tableNameSingular}}Find(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...)
|
2016-07-16 21:22:57 +10:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
2016-08-05 15:03:37 +10:00
|
|
|
return retobj
|
2016-07-16 21:22:57 +10:00
|
|
|
}
|
|
|
|
|
2016-08-01 15:10:10 +10:00
|
|
|
// {{$tableNameSingular}}Find retrieves a single record by ID with an executor.
|
2016-08-02 19:56:55 +10:00
|
|
|
// If selectCols is empty Find will return all columns.
|
2016-08-01 15:10:10 +10:00
|
|
|
func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
2016-06-10 18:53:15 +10:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-06-15 00:01:28 +10:00
|
|
|
|
2016-08-07 23:36:11 -07:00
|
|
|
sel := "*"
|
|
|
|
if len(selectCols) > 0 {
|
|
|
|
sel = strings.Join(strmangle.IdentQuoteSlice(selectCols), ",")
|
2016-04-17 19:25:09 +10:00
|
|
|
}
|
2016-08-07 23:36:11 -07:00
|
|
|
sql := fmt.Sprintf(
|
|
|
|
`select %s from "{{.Table.Name}}" where {{whereClause .Table.PKey.Columns 1}}`, sel,
|
|
|
|
)
|
|
|
|
q := boil.SQL(sql, {{$pkNames | join ", "}})
|
|
|
|
boil.SetExecutor(q, exec)
|
2016-04-17 19:25:09 +10:00
|
|
|
|
2016-08-07 23:07:15 -07:00
|
|
|
err := q.Bind({{$varNameSingular}})
|
2016-02-29 21:45:28 +10:00
|
|
|
if err != nil {
|
2016-06-19 16:00:37 -07:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %v", err)
|
2016-02-29 21:45:28 +10:00
|
|
|
}
|
|
|
|
|
2016-03-18 21:26:48 +10:00
|
|
|
return {{$varNameSingular}}, nil
|
2016-02-29 21:45:28 +10:00
|
|
|
}
|
2016-07-16 21:22:57 +10:00
|
|
|
|
2016-08-01 15:10:10 +10:00
|
|
|
// {{$tableNameSingular}}FindP retrieves a single record by ID with an executor, and panics on error.
|
|
|
|
func {{$tableNameSingular}}FindP(exec boil.Executor, {{$pkArgs}}, selectCols ...string) *{{$tableNameSingular}} {
|
2016-08-05 15:03:37 +10:00
|
|
|
retobj, err := {{$tableNameSingular}}Find(exec, {{$pkNames | join ", "}}, selectCols...)
|
2016-07-16 21:22:57 +10:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
2016-08-05 15:03:37 +10:00
|
|
|
return retobj
|
2016-07-16 21:22:57 +10:00
|
|
|
}
|