sqlboiler/templates/11_delete.tpl

130 lines
3.8 KiB
Smarty
Raw Normal View History

{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
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 {
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-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.
// Panics on error.
2016-08-01 07:10:10 +02:00
func (o *{{$tableNameSingular}}) DeleteGP() {
if err := o.DeleteG(); err != nil {
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 {
if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} provided for deletion")
}
var mods []qm.QueryMod
mods = append(mods,
2016-08-01 07:10:10 +02:00
qm.From("{{.Table.Name}}"),
qm.Where(`{{whereClause .Table.PKey.Columns 1}}`, {{.Table.PKey.Columns | stringMap .StringFuncs.titleCase | prefixStringSlice "o." | join ", "}}),
)
2016-08-01 07:10:10 +02:00
query := NewQuery(exec, mods...)
boil.SetDelete(query)
_, 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-08-01 07:10:10 +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.
2016-08-01 07:10:10 +02:00
func (o *{{$tableNameSingular}}) DeleteP(exec boil.Executor) {
if err := o.Delete(exec); err != nil {
panic(boil.WrapErr(err))
}
}
// DeleteAll deletes all rows.
func (o {{$varNameSingular}}Query) DeleteAll() error {
if o.Query == nil {
return errors.New("{{.PkgName}}: no {{$varNameSingular}}Query provided for delete all")
}
boil.SetDelete(o.Query)
_, err := boil.ExecQuery(o.Query)
if err != nil {
return fmt.Errorf("{{.PkgName}}: unable to delete all from {{.Table.Name}}: %s", err)
}
return nil
}
// DeleteAllP deletes all rows, and panics on error.
func (o {{$varNameSingular}}Query) DeleteAllP() {
if err := o.DeleteAll(); err != nil {
panic(boil.WrapErr(err))
}
}
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-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-08-01 07:10:10 +02:00
return o.DeleteAll(boil.GetDB())
}
2016-08-01 07:10:10 +02:00
// DeleteAll deletes all rows in the slice with an executor.
func (o {{$tableNameSingular}}Slice) DeleteAll(exec boil.Executor) error {
if o == nil {
return errors.New("{{.PkgName}}: no {{$tableNameSingular}} slice provided for delete all")
}
var mods []qm.QueryMod
args := o.inPrimaryKeyArgs()
in := boil.WherePrimaryKeyIn(len(o), {{.Table.PKey.Columns | stringMap .StringFuncs.quoteWrap | join ", "}})
mods = append(mods,
2016-08-01 07:10:10 +02:00
qm.From("{{.Table.Name}}"),
qm.Where(in, args...),
)
2016-08-01 07:10:10 +02:00
query := NewQuery(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)
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, args)
}
return nil
}
2016-08-01 07:10:10 +02:00
// DeleteAllP deletes all rows in the slice with 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))
}
}