Pass through sql.ErrNoRows for .Find() too
This commit is contained in:
parent
956157d057
commit
2b4508b228
1 changed files with 5 additions and 2 deletions
|
@ -28,15 +28,18 @@ func {{$tableNameSingular}}Find(exec boil.Executor, {{$pkArgs}}, selectCols ...s
|
||||||
if len(selectCols) > 0 {
|
if len(selectCols) > 0 {
|
||||||
sel = strings.Join(strmangle.IdentQuoteSlice(selectCols), ",")
|
sel = strings.Join(strmangle.IdentQuoteSlice(selectCols), ",")
|
||||||
}
|
}
|
||||||
sql := fmt.Sprintf(
|
query := fmt.Sprintf(
|
||||||
`select %s from "{{.Table.Name}}" where {{whereClause 1 .Table.PKey.Columns}}`, sel,
|
`select %s from "{{.Table.Name}}" where {{whereClause 1 .Table.PKey.Columns}}`, sel,
|
||||||
)
|
)
|
||||||
|
|
||||||
q := boil.SQL(sql, {{$pkNames | join ", "}})
|
q := boil.SQL(query, {{$pkNames | join ", "}})
|
||||||
boil.SetExecutor(q, exec)
|
boil.SetExecutor(q, exec)
|
||||||
|
|
||||||
err := q.Bind({{$varNameSingular}})
|
err := q.Bind({{$varNameSingular}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Cause(err) == sql.ErrNoRows {
|
||||||
|
return nil, sql.ErrNoRows
|
||||||
|
}
|
||||||
return nil, errors.Wrap(err, "{{.PkgName}}: unable to select from {{.Table.Name}}")
|
return nil, errors.Wrap(err, "{{.PkgName}}: unable to select from {{.Table.Name}}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue