Skip to content

Instantly share code, notes, and snippets.

@hauxe
Created July 3, 2018 08:42
Show Gist options
  • Save hauxe/381d8cf39c952ba43670a9ca63cf16f7 to your computer and use it in GitHub Desktop.
Save hauxe/381d8cf39c952ba43670a9ca63cf16f7 to your computer and use it in GitHub Desktop.
func (crud *CRUD) Delete(data interface{}) (int64, error) {
rv := reflect.ValueOf(data)
rv = reflect.Indirect(rv)
pk := rv.Field(crud.Config.pk.index)
if !pk.CanInterface() {
return 0, errors.Errorf("table %s with primary key has wrong interface type",
crud.Config.TableName, crud.Config.pk.index)
}
result, err := crud.Config.DB.Exec(crud.Config.sqlCRUDDelete, pk.Interface())
if err != nil {
return 0, errors.Wrap(err, "error crud delete")
}
return result.RowsAffected()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment