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