2016-03-23 07:18:41 +01:00
|
|
|
{{- $tableNameSingular := titleCaseSingular .Table.Name -}}
|
2016-03-18 12:26:48 +01:00
|
|
|
// {{$tableNameSingular}}Delete deletes a single record.
|
|
|
|
func {{$tableNameSingular}}Delete(db boil.DB, id int) error {
|
2016-03-23 04:03:35 +01:00
|
|
|
if id == 0 {
|
2016-03-23 07:18:41 +01:00
|
|
|
return errors.New("{{.PkgName}}: no id provided for {{.Table.Name}} delete")
|
2016-02-23 13:51:49 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 07:18:41 +01:00
|
|
|
_, err := db.Exec("DELETE FROM {{.Table.Name}} WHERE id=$1", id)
|
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-03-23 07:18:41 +01:00
|
|
|
{{if hasPrimaryKey .Table.Columns -}}
|
2016-03-18 16:27:55 +01:00
|
|
|
// Delete deletes a single {{$tableNameSingular}} record.
|
|
|
|
// Delete will match against the primary key column to find the record to delete.
|
2016-03-23 04:03:35 +01:00
|
|
|
func (o *{{$tableNameSingular}}) Delete(db boil.DB) error {
|
2016-03-23 07:18:41 +01:00
|
|
|
{{- $pkeyName := getPrimaryKey .Table.Columns -}}
|
|
|
|
_, err := db.Exec("DELETE FROM {{.Table.Name}} WHERE {{$pkeyName}}=$1", o.{{titleCase $pkeyName}})
|
2016-03-18 16:27:55 +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-03-18 16:27:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
{{- end}}
|