sqlboiler/cmds/templates/delete.tpl

15 lines
444 B
Smarty
Raw Normal View History

2016-02-23 13:51:49 +01:00
{{- $tableName := .TableName -}}
// {{makeGoColName $tableName}}Delete deletes a single record.
func {{makeGoColName $tableName}}Delete(db *sqlx.DB, id int) error {
2016-02-23 13:51:49 +01:00
if id == nil {
return nil, errors.New("model: no id provided for {{$tableName}} delete")
2016-02-23 13:51:49 +01:00
}
err := db.Exec("DELETE FROM {{$tableName}} WHERE id=$1", id)
if err != nil {
return errors.New("model: unable to delete from {{$tableName}}: %s", err)
2016-02-23 13:51:49 +01:00
}
return nil
}