2016-04-25 03:43:09 +02:00
|
|
|
{{- if hasPrimaryKey .Table.PKey -}}
|
2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
|
|
|
{{- $dbName := singular .Table.Name -}}
|
|
|
|
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$tableNameSingular}}Find retrieves a single record by ID.
|
2016-04-26 11:27:00 +02:00
|
|
|
func {{$tableNameSingular}}Find({{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
2016-05-06 11:31:51 +02:00
|
|
|
return {{$tableNameSingular}}FindX(boil.GetDB(), {{camelCaseCommaList "" .Table.PKey.Columns}}, selectCols...)
|
2016-04-24 07:33:05 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 11:27:00 +02:00
|
|
|
func {{$tableNameSingular}}FindX(exec boil.Executor, {{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, selectCols ...string) (*{{$tableNameSingular}}, error) {
|
2016-04-24 07:33:05 +02:00
|
|
|
var {{$varNameSingular}} *{{$tableNameSingular}}
|
|
|
|
mods := []qs.QueryMod{
|
2016-04-26 11:27:00 +02:00
|
|
|
qs.Select(selectCols...),
|
|
|
|
qs.Table("{{.Table.Name}}"),
|
2016-05-06 11:31:51 +02:00
|
|
|
qs.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{camelCaseCommaList "" .Table.PKey.Columns}}),
|
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-04-26 11:27:00 +02:00
|
|
|
err := boil.ExecQueryOne(q).Scan(boil.GetStructPointers(&{{$varNameSingular}}, selectCols...)...)
|
2016-02-29 12:45:28 +01:00
|
|
|
|
|
|
|
if err != nil {
|
2016-03-23 07:18:41 +01:00
|
|
|
return nil, fmt.Errorf("{{.PkgName}}: unable to select from {{.Table.Name}}: %s", 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
|
|
|
}
|
2016-04-25 03:43:09 +02:00
|
|
|
{{- end -}}
|