luckyframework / avram

A Crystal database wrapper for reading, writing, and migrating Postgres databases.
https://luckyframework.github.io/avram/
MIT License
165 stars 64 forks source link

Run delete operation in a transaction #1052

Open akadusei opened 6 days ago

akadusei commented 6 days ago

https://github.com/luckyframework/avram/blob/bec90582181bed458e1c36d0497b8fce3353306f/src/avram/delete_operation.cr#L38

I'm wondering if Avram::DeleteOperation#delete should use a transaction, like its SaveOperation#save counterpart. This should enable an after_commit callback counterpart for delete operations.

jwoertink commented 6 days ago

I think this makes sense. One thing that may need to change is this section

https://github.com/luckyframework/avram/blob/bec90582181bed458e1c36d0497b8fce3353306f/src/avram/delete_operation.cr#L106-L114

Since these make calls out, I don't think we have direct control over the SQL. Whomever takes this on could try doing something like

db.transaction do
  # ... code
end

but if that doesn't work, then just a refactor to bring the proper SQL in here for it would be fine.