fukamachi / mito

An ORM for Common Lisp with migrations, relationships and PostgreSQL support
284 stars 31 forks source link

transactions and rollbacks. #102

Open eko234 opened 3 years ago

eko234 commented 3 years ago

Does mito exposes a way to explicitly handle transactions? I have a use case in which I would like to update a object along with objects related to it, i.e. an album and it's songs, I'm not aware of a way to update nested objects with mito, I can do it in an iterative way though. The thing is I would like the transaction to rollback if an operation with an object related to the main object fails or if I explicitly raise a condition, is there a way to do it in mito?

vindarel commented 3 years ago

There's a hint for transactions here: https://github.com/fukamachi/caveman/issues/69

(defmacro with-transaction (&body body)
  `(cl-dbi:with-transaction *connection*
     ,@body))
zen-wq commented 2 years ago

@eko234 I have a transactions library for mito here https://code.rhodecode.com/u/someseven/mito-transactions

I used it in two non-published (yet) projects and there are somewhat comprehensive tests.

eko234 commented 2 years ago

@eko234 I have a transactions library for mito here https://code.rhodecode.com/u/someseven/mito-transactions

I used it in two non-published (yet) projects and there are somewhat comprehensive tests.

Cool, thank you so much.

zen-wq commented 2 years ago

@eko234 For your use-case just replace mito package with mito-transactions and wrap transaction code in (mito-transactions:with-transaction () ...). It redefines deftable and simply reexports the rest of mito so no other behaviour should change. cl-dbi:with-transaction only handles the database. mito-transactions:with-transaction makes sure in-image DAOs are also kept valid.