sqlboiler/cmds/templates/delete.tpl

35 lines
1.3 KiB
Smarty
Raw Normal View History

{{if hasPrimaryKey .Table.PKey -}}
2016-03-23 07:18:41 +01:00
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
{{- $varNameSingular := camelCaseSingular .Table.Name -}}
// Delete deletes a single {{$tableNameSingular}} record.
// Delete will match against the primary key column to find the record to delete.
func (o *{{$tableNameSingular}}) Delete(mods ...QueryMod) error {
return o.DeleteX(boil.GetDB(), mods...)
}
func (o *{{$tableNameSingular}}) DeleteX(exec boil.Executor, mods ...QueryMod) error {
mods = append(mods,
boil.From("{{.table.Name}}"),
boil.Where("{{wherePrimaryKey .Table.Pkey.Columns 1}}", {{paramsPrimaryKey "o." .Table.PKey.Columns true}}),
)
query := NewQueryX(exec, mods...)
_, err := exec.Exec("DELETE FROM {{.Table.Name}} WHERE {{wherePrimaryKey .Table.PKey.Columns 1}}", {{paramsPrimaryKey "o." .Table.PKey.Columns true}})
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
}
func (o {{$varNameSingular}}Query) DeleteAll() error {
2016-04-04 12:28:58 +02:00
_, err := db.Exec("DELETE FROM {{.Table.Name}} WHERE {{wherePrimaryKey .Table.PKey.Columns 1}}", {{paramsPrimaryKey "o." .Table.PKey.Columns true}})
if err != nil {
2016-03-23 07:18:41 +01:00
return fmt.Errorf("{{.PkgName}}: unable to delete from {{.Table.Name}}: %s", err)
}
return nil
}
{{- end}}