2016-04-04 12:28:58 +02:00
|
|
|
{{if hasPrimaryKey .Table.PKey -}}
|
2016-04-17 11:25:09 +02:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
|
|
|
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
|
2016-03-19 07:22:10 +01:00
|
|
|
// Update updates a single {{$tableNameSingular}} record.
|
2016-04-13 15:51:58 +02:00
|
|
|
// whitelist is a list of column_name's that should be updated.
|
2016-03-19 07:22:10 +01:00
|
|
|
// Update will match against the primary key column to find the record to update.
|
|
|
|
// WARNING: This Update method will NOT ignore nil members.
|
|
|
|
// If you pass in nil members, those columnns will be set to null.
|
2016-04-17 11:25:09 +02:00
|
|
|
func (o *{{$tableNameSingular}}) Update(whitelist ... string) error {
|
|
|
|
return o.UpdateX(boil.GetDB(), whitelist...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *{{$tableNameSingular}}) UpdateX(exec boil.Executor, whitelist ... string) error {
|
2016-04-13 15:51:58 +02:00
|
|
|
if err := o.doBeforeUpdateHooks(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(whitelist) == 0 {
|
2016-05-05 11:01:24 +02:00
|
|
|
whitelist = {{$varNameSingular}}ColumnsWithoutDefault
|
|
|
|
whitelist = append(boil.NonZeroDefaultSet({{$varNameSingular}}ColumnsWithDefault, o), whitelist...)
|
|
|
|
whitelist = boil.SetComplement(whitelist, {{$varNameSingular}}PrimaryKeyColumns)
|
|
|
|
whitelist = boil.SetComplement(whitelist, {{$varNameSingular}}AutoIncrementColumns)
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
if len(whitelist) != 0 {
|
2016-05-03 15:42:25 +02:00
|
|
|
query := fmt.Sprintf(`UPDATE {{.Table.Name}} SET %s WHERE %s`, boil.SetParamNames(whitelist), boil.WherePrimaryKey(len(whitelist)+1, {{commaList .Table.PKey.Columns}}))
|
2016-05-05 11:01:24 +02:00
|
|
|
_, err = exec.Exec(query, boil.GetStructValues(o, whitelist...), {{paramsPrimaryKey "o." .Table.PKey.Columns true}})
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}}, could not build a whitelist for row: %s")
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
|
2016-03-19 07:22:10 +01:00
|
|
|
if err != nil {
|
2016-04-04 12:28:58 +02:00
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to update {{.Table.Name}} row: %s", err)
|
2016-03-19 07:22:10 +01:00
|
|
|
}
|
|
|
|
|
2016-04-13 15:51:58 +02:00
|
|
|
if err := o.doAfterUpdateHooks(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-03-19 07:22:10 +01:00
|
|
|
return nil
|
|
|
|
}
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-05-05 11:01:24 +02:00
|
|
|
func (o *{{$tableNameSingular}}) UpdateAt({{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, whitelist ...string) error {
|
|
|
|
return o.UpdateAtX(boil.GetDB(), {{camelCaseCommaList .Table.PKey.Columns}}, whitelist...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *{{$tableNameSingular}}) UpdateAtX(exec boil.Executor, {{primaryKeyFuncSig .Table.Columns .Table.PKey.Columns}}, whitelist ...string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-03 15:42:25 +02:00
|
|
|
func (v {{$varNameSingular}}Query) UpdateAll(cols M) error {
|
|
|
|
return nil
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
2016-03-19 07:22:10 +01:00
|
|
|
{{- end}}
|