[ORM] Nested transactions emulation
Eloquent should implement nested transaction emulation. This simple trick will ensure that you can use a transaction inside other transaction safely. Also it speeds up integration and functional testing.
As you know, MySQL does not support nested transactions. Most of ORMs emulate them by creating a simple counter $activeTransactions = 0 (or using MySQL savepoints). When a new transaction startes counter is incremented. When transaction finishes, and $activeTransactions > 1 counter is decremented, but commit / rollback is not executed.
In other words: commit/rollback will be executed only for the first transaction started.
Take a look in Doctrine DBAL Transaction for reference:
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php#L1031 https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php#L1049
This helps in testing purposes as it may perform fast database cleanups by rolling back the active transaction. But it's worth and simple feature on it's own.
With this feature we can improve Laravel4 module in Codeception for data auto cleanup.
Does GitHub really not have a +1 button?
Well...+1
:+1:
I implemented a custom transaction method in L3 just a because of this, too.
+1
:+1:.
So is this only a MySQL thing? Other databases support nested transactions fine?
100% for Postgres and probably Oracle/MSSql too. Except SQLite (he-he).
@taylorotwell Both MySQL and Postgres use "SavePoints" to emulate a nested transaction.
However, even without save-point support, it would be nice if the ORM supported the ability to recognize when it was inside a transaction and continue the transaction without throwing a PDO error, like so: http://www.php.net/manual/en/pdo.begintransaction.php#109753
Done. We can add in the save point stuff later if we want.
Thanks @taylorotwell! Let me know if I can be of any help with this feature.
+1
@taylorotwell This would be so useful.
:+1: looking forward
+1
+1 any news? :D
This is already done.
On Fri, Nov 27, 2015 at 11:38 AM, Alfredo Concha [email protected] wrote:
+1
any news? :D
Reply to this email directly or view it on GitHub: https://github.com/laravel/framework/issues/1686#issuecomment-160180910
HAHAHAHHA :smile: