Refactor some awkward looking bits
This commit is contained in:
parent
5360d3094e
commit
1ac3853d3c
2 changed files with 13 additions and 21 deletions
|
@ -43,30 +43,25 @@ func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string
|
|||
|
||||
wl := o.generateUpdateColumns(whitelist...)
|
||||
|
||||
if len(wl) != 0 {
|
||||
query = fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, strmangle.SetParamNames(wl), strmangle.WhereClause(len(wl)+1, {{$varNameSingular}}PrimaryKeyColumns))
|
||||
values = boil.GetStructValues(o, wl...)
|
||||
values = append(values, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, query)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
_, err = exec.Exec(query, values...)
|
||||
} else {
|
||||
if len(wl) == 0 {
|
||||
return errors.New("{{.PkgName}}: unable to update {{.Table.Name}}, could not build whitelist")
|
||||
}
|
||||
|
||||
query = fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, strmangle.SetParamNames(wl), strmangle.WhereClause(len(wl)+1, {{$varNameSingular}}PrimaryKeyColumns))
|
||||
values = boil.GetStructValues(o, wl...)
|
||||
values = append(values, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}})
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, query)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
_, err = exec.Exec(query, values...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "{{.PkgName}}: unable to update {{.Table.Name}} row")
|
||||
}
|
||||
|
||||
if err := o.doAfterUpdateHooks(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return o.doAfterUpdateHooks()
|
||||
}
|
||||
|
||||
// UpdateAllP updates all rows with matching column names, and panics on error.
|
||||
|
|
|
@ -13,10 +13,7 @@ func {{$tableNameSingular}}Exists(exec boil.Executor, {{$pkArgs}}) (bool, error)
|
|||
fmt.Fprintln(boil.DebugWriter, {{$pkNames | join ", "}})
|
||||
}
|
||||
|
||||
row := exec.QueryRow(
|
||||
sql,
|
||||
{{$pkNames | join ", "}},
|
||||
)
|
||||
row := exec.QueryRow(sql, {{$pkNames | join ", "}})
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue