2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-04-17 11:25:09 +02:00
|
|
|
// 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 {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion")
|
|
|
|
}
|
|
|
|
|
2016-04-23 13:54:24 +02:00
|
|
|
return o.DeleteX(boil.GetDB())
|
2016-04-19 04:02:32 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 13:22:57 +02:00
|
|
|
// DeleteP deletes a single {{$tableNameSingular}} record.
|
|
|
|
// DeleteP will match against the primary key column to find the record to delete.
|
|
|
|
// Panics on error.
|
|
|
|
func (o *{{$tableNameSingular}}) DeleteP() {
|
|
|
|
if err := o.Delete(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteX deletes a single {{$tableNameSingular}} record with an executor.
|
|
|
|
// DeleteX will match against the primary key column to find the record to delete.
|
2016-04-23 13:54:24 +02:00
|
|
|
func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor) error {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion")
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:01:28 +02:00
|
|
|
var mods []qm.QueryMod
|
2016-04-23 13:54:24 +02:00
|
|
|
|
2016-04-19 04:02:32 +02:00
|
|
|
mods = append(mods,
|
2016-06-14 16:01:28 +02:00
|
|
|
qm.Table("{{.Table.Name}}"),
|
2016-06-26 05:17:39 +02:00
|
|
|
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}),
|
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-07-16 13:22:57 +02:00
|
|
|
// DeleteXP deletes a single {{$tableNameSingular}} record with an executor.
|
|
|
|
// DeleteXP will match against the primary key column to find the record to delete.
|
|
|
|
// Panics on error.
|
|
|
|
func (o *{{$tableNameSingular}}) DeleteXP(exec boil.Executor) {
|
|
|
|
if err := o.DeleteX(exec); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteAll deletes all rows.
|
2016-04-17 11:25:09 +02:00
|
|
|
func (o {{$varNameSingular}}Query) DeleteAll() error {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o.Query == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$varNameSingular}}Query provided for delete all")
|
|
|
|
}
|
2016-04-23 13:54:24 +02:00
|
|
|
|
2016-04-26 11:27:00 +02:00
|
|
|
boil.SetDelete(o.Query)
|
|
|
|
|
|
|
|
_, err := boil.ExecQuery(o.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
|
|
|
|
}
|
|
|
|
|
2016-07-16 13:22:57 +02:00
|
|
|
// DeleteAllP deletes all rows, and panics on error.
|
|
|
|
func (o {{$varNameSingular}}Query) DeleteAllP() {
|
|
|
|
if err := o.DeleteAll(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteAll deletes all rows in the slice.
|
2016-07-16 16:15:14 +02:00
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAll() error {
|
2016-04-26 11:27:00 +02:00
|
|
|
if o == nil {
|
|
|
|
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
|
|
|
|
}
|
|
|
|
return o.DeleteAllX(boil.GetDB())
|
2016-04-23 13:54:24 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 13:22:57 +02:00
|
|
|
// DeleteAll deletes all rows in the slice.
|
2016-07-16 16:15:14 +02:00
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAllP() {
|
2016-07-16 13:22:57 +02:00
|
|
|
if err := o.DeleteAll(); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteAllX deletes all rows in the slice with an executor.
|
2016-07-16 16:15:14 +02:00
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAllX(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-06-14 16:01:28 +02:00
|
|
|
var mods []qm.QueryMod
|
2016-04-23 13:54:24 +02:00
|
|
|
|
|
|
|
args := o.inPrimaryKeyArgs()
|
2016-06-20 07:57:46 +02:00
|
|
|
in := boil.WherePrimaryKeyIn(len(o), {{.Table.PKey.Columns | stringMap .StringFuncs.quoteWrap | join ", "}})
|
2016-04-23 13:54:24 +02:00
|
|
|
|
|
|
|
mods = append(mods,
|
2016-06-14 16:01:28 +02:00
|
|
|
qm.Table("{{.Table.Name}}"),
|
|
|
|
qm.Where(in, args...),
|
2016-04-23 13:54:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-06-10 06:40:02 +02:00
|
|
|
if boil.DebugMode {
|
|
|
|
fmt.Fprintln(boil.DebugWriter, args)
|
|
|
|
}
|
2016-03-18 16:27:55 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-07-16 13:22:57 +02:00
|
|
|
|
|
|
|
// DeleteAllXP deletes all rows in the slice with an executor, and panics on error.
|
2016-07-16 16:15:14 +02:00
|
|
|
func (o {{$tableNameSingular}}Slice) DeleteAllXP(exec boil.Executor) {
|
2016-07-16 13:22:57 +02:00
|
|
|
if err := o.DeleteAllX(exec); err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
}
|