mito icon indicating copy to clipboard operation
mito copied to clipboard

transactions and rollbacks.

Open eko234 opened this issue 3 years ago • 4 comments

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?

eko234 avatar Jul 19 '21 23:07 eko234

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))

vindarel avatar Jul 21 '21 12:07 vindarel

@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.

zen-wq avatar Oct 07 '21 13:10 zen-wq

@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.

eko234 avatar Oct 07 '21 14:10 eko234

@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.

zen-wq avatar Oct 07 '21 17:10 zen-wq