2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-09 12:19:42 +02:00
|
|
|
// DeleteP deletes a single {{$tableNameSingular}} record with an executor.
|
|
|
|
// DeleteP will match against the primary key column to find the record to delete.
|
|
|
|
// Panics on error.
|
|
|
|
func (o *{{$tableNameSingular}}) DeleteP(exec boil.Executor) {
|
|
|
|
if err := o.Delete(exec); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// DeleteG deletes a single {{$tableNameSingular}} record.
|
|
|
|
// DeleteG will match against the primary key column to find the record to delete.
|
|
|
|
func (o *{{$tableNameSingular}}) DeleteG() error {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion")
|
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
return o.Delete(boil.GetDB())
|
2016-04-19 04:02:32 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// DeleteGP deletes a single {{$tableNameSingular}} record.
|
|
|
|
// DeleteGP will match against the primary key column to find the record to delete.
|
2016-07-16 13:22:57 +02:00
|
|
|
// Panics on error.
|
2016-08-01 07:10:10 +02:00
|
|
|
func (o *{{$tableNameSingular}}) DeleteGP() {
|
|
|
|
if err := o.DeleteG(); err != nil {
|
2016-07-16 13:22:57 +02:00
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// Delete deletes a single {{$tableNameSingular}} record with an executor.
|
|
|
|
// Delete will match against the primary key column to find the record to delete.
|
|
|
|
func (o *{{$tableNameSingular}}) Delete(exec boil.Executor) error {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o == nil {
|
2016-08-13 21:07:13 +02:00
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for delete")
|
2016-04-26 11:27:00 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
{{if not .NoHooks -}}
|
|
|
|
if err := o.doBeforeDeleteHooks(exec); err != nil {
|
2016-08-28 14:16:08 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
|
2016-08-13 21:07:13 +02:00
|
|
|
args := o.inPrimaryKeyArgs()
|
2016-04-23 13:54:24 +02:00
|
|
|
|
2016-09-08 23:23:10 +02:00
|
|
|
sql := `DELETE FROM {{schemaTable .DriverName .Schema .Table.Name}} WHERE {{whereClause 1 .Table.PKey.Columns}}`
|
2016-04-19 04:02:32 +02:00
|
|
|
|
2016-08-13 21:07:13 +02:00
|
|
|
if boil.DebugMode {
|
|
|
|
fmt.Fprintln(boil.DebugWriter, sql)
|
|
|
|
fmt.Fprintln(boil.DebugWriter, args...)
|
|
|
|
}
|
2016-04-19 04:02:32 +02:00
|
|
|
|
2016-08-13 21:07:13 +02:00
|
|
|
_, err := exec.Exec(sql, args...)
|
2016-02-23 13:51:49 +01:00
|
|
|
if err != nil {
|
2016-08-13 20:36:03 +02:00
|
|
|
return errors.Wrap(err, "{{.PkgName}}: unable to delete from {{.Table.Name}}")
|
2016-02-23 13:51:49 +01:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
{{if not .NoHooks -}}
|
|
|
|
if err := o.doAfterDeleteHooks(exec); err != nil {
|
2016-08-28 14:16:08 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
|
2016-02-23 13:51:49 +01:00
|
|
|
return nil
|
|
|
|
}
|
2016-03-18 16:27:55 +01:00
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
// DeleteAllP deletes all rows, and panics on error.
|
|
|
|
func (q {{$varNameSingular}}Query) DeleteAllP() {
|
2016-08-13 18:16:10 +02:00
|
|
|
if err := q.DeleteAll(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
2016-07-16 13:22:57 +02:00
|
|
|
}
|
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
// DeleteAll deletes all matching rows.
|
|
|
|
func (q {{$varNameSingular}}Query) DeleteAll() error {
|
|
|
|
if q.Query == nil {
|
2016-04-26 11:27:00 +02:00
|
|
|
return errors.New("{{.PkgName}}: no {{$varNameSingular}}Query provided for delete all")
|
|
|
|
}
|
2016-04-23 13:54:24 +02:00
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
boil.SetDelete(q.Query)
|
2016-04-26 11:27:00 +02:00
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
_, err := boil.ExecQuery(q.Query)
|
2016-03-18 16:27:55 +01:00
|
|
|
if err != nil {
|
2016-08-13 20:36:03 +02:00
|
|
|
return errors.Wrap(err, "{{.PkgName}}: unable to delete all from {{.Table.Name}}")
|
2016-04-23 13:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// DeleteAll deletes all rows in the slice, and panics on error.
|
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAllGP() {
|
|
|
|
if err := o.DeleteAllG(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
2016-04-26 11:27:00 +02:00
|
|
|
}
|
2016-04-23 13:54:24 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// DeleteAllG deletes all rows in the slice.
|
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAllG() error {
|
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
|
2016-07-16 13:22:57 +02:00
|
|
|
}
|
2016-08-01 07:10:10 +02:00
|
|
|
return o.DeleteAll(boil.GetDB())
|
2016-07-16 13:22:57 +02:00
|
|
|
}
|
|
|
|
|
2016-08-09 12:19:42 +02:00
|
|
|
// DeleteAllP deletes all rows in the slice, using an executor, and panics on error.
|
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAllP(exec boil.Executor) {
|
|
|
|
if err := o.DeleteAll(exec); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteAll deletes all rows in the slice, using an executor.
|
2016-08-01 07:10:10 +02:00
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
|
|
|
|
}
|
|
|
|
|
2016-08-09 07:57:54 +02:00
|
|
|
if len(o) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2016-04-23 13:54:24 +02:00
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
{{if not .NoHooks -}}
|
2016-08-28 14:16:08 +02:00
|
|
|
if len({{$varNameSingular}}BeforeDeleteHooks) != 0 {
|
|
|
|
for _, obj := range o {
|
2016-08-29 14:38:19 +02:00
|
|
|
if err := obj.doBeforeDeleteHooks(exec); err != nil {
|
2016-08-28 14:16:08 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
|
2016-04-23 13:54:24 +02:00
|
|
|
args := o.inPrimaryKeyArgs()
|
|
|
|
|
2016-08-09 07:57:54 +02:00
|
|
|
sql := fmt.Sprintf(
|
2016-09-08 23:23:10 +02:00
|
|
|
`DELETE FROM {{schemaTable .DriverName .Schema .Table.Name}} WHERE (%s) IN (%s)`,
|
2016-08-11 14:26:49 +02:00
|
|
|
strings.Join(strmangle.IdentQuoteSlice({{$varNameSingular}}PrimaryKeyColumns), ","),
|
2016-08-09 07:57:54 +02:00
|
|
|
strmangle.Placeholders(len(o) * len({{$varNameSingular}}PrimaryKeyColumns), 1, len({{$varNameSingular}}PrimaryKeyColumns)),
|
2016-04-23 13:54:24 +02:00
|
|
|
)
|
|
|
|
|
2016-06-10 06:40:02 +02:00
|
|
|
if boil.DebugMode {
|
2016-08-13 18:16:10 +02:00
|
|
|
fmt.Fprintln(boil.DebugWriter, sql)
|
|
|
|
fmt.Fprintln(boil.DebugWriter, args)
|
2016-06-10 06:40:02 +02:00
|
|
|
}
|
2016-03-18 16:27:55 +01:00
|
|
|
|
2016-08-13 18:58:18 +02:00
|
|
|
_, err := exec.Exec(sql, args...)
|
|
|
|
if err != nil {
|
2016-08-13 20:36:03 +02:00
|
|
|
return errors.Wrap(err, "{{.PkgName}}: unable to delete all from {{$varNameSingular}} slice")
|
2016-08-13 18:58:18 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
{{if not .NoHooks -}}
|
2016-08-28 14:16:08 +02:00
|
|
|
if len({{$varNameSingular}}AfterDeleteHooks) != 0 {
|
|
|
|
for _, obj := range o {
|
2016-08-29 14:38:19 +02:00
|
|
|
if err := obj.doAfterDeleteHooks(exec); err != nil {
|
2016-08-28 14:16:08 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
|
2016-03-18 16:27:55 +01:00
|
|
|
return nil
|
|
|
|
}
|