New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nesting transactions #1505
Comments
I'm super interested in this as well. The unit of work experience in entity framework is fantastic, however the technical limitations of the javascript/node seem to make that impossible without a sort of |
What's the current workaround for this, if any @pleerock ? |
+1. I would really like to set up nested transactions so that I can do db integration tests without having to re-seed the database for every test. |
Hi All, Hope this helps, |
Hey @AlexMesser and @pleerock, is there some progress with this? Having some ideas on how to tackle the issue. The solutions I'm thinking about involves detecting if there's a transaction open at the database level, which would not only solve the nested transaction issue but also allow greater control over how Typeorm manages the transactions currently. The algorithm goes as follows:
I made failing tests for both use cases at #3921. |
You can check if a transaction is in progress using the if (repo.queryRunner.isTransactionActive) {
// run your runInTransaction stuff here
} else {
repo.manager.transaction(async manager => {
// run your runInTransaction stuff here
});
} |
What would happen in case of starting a transaction inside another?
Since nested transactions are not allowed, does |
@lopezm94 localEntityManager1 and localEntityManager2 are the same object, so you'd get an error saying something like "transaction in already in progress" |
Any progress on this? |
I can contribute an implementation of this using SAVEPOINTs on supported databases and open a PR. Would it be acceptable? |
@lbguilherme did you get to start on this? I'm considering starting a similar effort |
@burgalon Please do. I couldn't find time for this yet. |
+1 |
* feat: add nested transaction This will allow nested transaction for postgres driver using "save point" Closes: #1505 * package-lock.json * removed `RELEASE SAVEPOINT` from OracleQueryRunner * fixed transaction support in sqljs-based drivers * improved nested transactions logic across all drivers; code refactoring; * added nested transactions support for mssql * fixed failing test Co-authored-by: mortzprk <mortz.prk@gmail.com> Co-authored-by: AlexMesser
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[x]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
websql
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)I have a transactional method and from it i call other transactional methods. When i do this the other method create a new transaction, there are any option to create a nested transaction ? Something like the propagation options of jpa/spring transaction.
The code above illustrate the question.
Steps to reproduce or a small repository showing the problem:
The text was updated successfully, but these errors were encountered: