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 -}}
|
|
|
|
{{- $pkArgs := joinSlices " " $pkNames $colDefs.Types | join ", "}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$tableNameSingular}}Find retrieves a single record by ID.
|
2016-06-27 08:56:05 +02:00
|
|
|
func {{$tableNameSingular}}Find({{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
|
|
|
return {{$tableNameSingular}}FindX(boil.GetDB(), {{$pkNames | join ", "}}, selectCols...)
|
2016-04-24 07:33:05 +02:00
|
|
|
}
|
|
|
|
|
2016-06-27 08:56:05 +02:00
|
|
|
func {{$tableNameSingular}}FindX(exec boil.Executor, {{$pkArgs}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
2016-06-10 10:53:15 +02:00
|
|
|
{{$varNameSingular}} := &{{$tableNameSingular}}{}
|
2016-06-14 16:01:28 +02:00
|
|
|
|
|
|
|
mods := []qm.QueryMod{
|
|
|
|
qm.Select(selectCols...),
|
|
|
|
qm.Table("{{.Table.Name}}"),
|
2016-06-27 08:56:05 +02:00
|
|
|
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{$pkNames | join ", "}}),
|
2016-04-17 11:25:09 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 07:33:05 +02:00
|
|
|
q := NewQueryX(exec, mods...)
|
2016-04-17 11:25:09 +02:00
|
|
|
|
2016-06-10 10:53:15 +02:00
|
|
|
err := boil.ExecQueryOne(q).Scan(boil.GetStructPointers({{$varNameSingular}}, selectCols...)...)
|
2016-02-29 12:45:28 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-06-20 01:00:37 +02:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %v", err)
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 12:26:48 +01:00
|
|
|
return {{$varNameSingular}}, nil
|
2016-02-29 12:45:28 +01:00
|
|
|
}
|