2016-04-17 11:25:09 +02:00
|
|
|
{{if hasPrimaryKey .Table.PKey -}}
|
2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
2016-04-17 11:25:09 +02:00
|
|
|
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
|
|
|
|
// Delete deletes a single {{$tableNameSingular}} record.
|
|
|
|
// Delete will match against the primary key column to find the record to delete.
|
2016-04-23 13:54:24 +02:00
|
|
|
func (o *{{$tableNameSingular}}) Delete() error {
|
|
|
|
return o.DeleteX(boil.GetDB())
|
2016-04-19 04:02:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-23 13:54:24 +02:00
|
|
|
func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error {
|
|
|
|
var mods []qs.QueryMod
|
|
|
|
|
2016-04-19 04:02:32 +02:00
|
|
|
mods = append(mods,
|
2016-04-23 13:54:24 +02:00
|
|
|
qs.From("{{.Table.Name}}"),
|
|
|
|
qs.Where("{{wherePrimaryKey .Table.PKey.Columns 1}}", {{paramsPrimaryKey "o." .Table.PKey.Columns true}}),
|
2016-04-19 04:02:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
query := NewQueryX(exec, mods...)
|
2016-04-23 13:54:24 +02:00
|
|
|
boil.SetDelete(query)
|
2016-04-19 04:02:32 +02:00
|
|
|
|
2016-04-23 13:54:24 +02:00
|
|
|
_, err := boil.ExecQuery(query)
|
2016-02-23 13:51:49 +01:00
|
|
|
if err != nil {
|
2016-03-23 07:18:41 +01:00
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to delete from {{.Table.Name}}: %s", err)
|
2016-02-23 13:51:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-18 16:27:55 +01:00
|
|
|
|
2016-04-17 11:25:09 +02:00
|
|
|
func (o {{$varNameSingular}}Query) DeleteAll() error {
|
2016-04-23 13:54:24 +02:00
|
|
|
boil.SetDelete(o)
|
|
|
|
|
|
|
|
_, err := boil.ExecQuery(query)
|
2016-03-18 16:27:55 +01:00
|
|
|
if err != nil {
|
2016-04-23 13:54:24 +02:00
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to delete all from {{.Table.Name}}: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o {{$varNameSingular}}Slice) DeleteAll() error {
|
|
|
|
return DeleteAllX(boil.GetDB())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o {{$varNameSingular}}Slice) DeleteAllX(exec boil.Executor) error {
|
|
|
|
var mods []qs.QueryMod
|
|
|
|
|
|
|
|
args := o.inPrimaryKeyArgs()
|
|
|
|
in := boil.WherePrimaryKeyIn(len(o), {{primaryKeyStrList .Table.PKey.Columns}})
|
|
|
|
|
|
|
|
mods = append(mods,
|
|
|
|
qs.From("{{.Table.Name}}"),
|
|
|
|
qs.Where(in, args...),
|
|
|
|
)
|
|
|
|
|
|
|
|
query := NewQueryX(exec, mods...)
|
|
|
|
boil.SetDelete(query)
|
|
|
|
|
|
|
|
_, err := boil.ExecQuery(query)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("{{.PkgName}}: unable to delete all from {{$varNameSingular}} slice: %s", err)
|
2016-03-18 16:27:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-04-19 04:02:32 +02:00
|
|
|
{{- end}}
|