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