Transactions - commit manual managed transaction
See original GitHub issueWhat you are doing?
I want to create a transaction and control which queries it will run. I want to do that using node 7.8.0 and async/await syntax. Here is a sample of the code I’m trying to run -
const transaction = await db.sequelize.transaction();
await db.User.create({ username: 'roy' }, { transaction });
await transaction.commit();
What do you expect to happen?
The transaction to complete
What is actually happening?
I get this error-
commit has been called on this transaction(3b1ab60a-172c-4795-9ace-b89b855c92ce), you can no longer use it. (The rejected query is attached as the 'sql' property of this error)
btw, if I run my code without using transactions it works. I just want to understand how to use transactions the right way using async/await.
Thanks.
Dialect: postgres Sequelize version: 4.0.0-2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:9
Top Results From Across the Web
java - How to manually commit a managed transaction
Overall, I would say that it's usually a good idea to let the container manage your transactions, as a transaction is usually in...
Read more >Container-Managed Transactions - The Java EE 6 Tutorial
In an enterprise bean with container-managed transaction demarcation, the EJB container sets the boundaries of the transactions.
Read more >Transactions - Sequelize
Managed transactions handle committing or rolling back the transaction automatically. You start a managed transaction by passing a callback to sequelize.
Read more >COMMIT TRANSACTION (Transact-SQL) - SQL Server
When used in nested transactions, commits of the inner transactions don't free resources or make their modifications permanent. The data ...
Read more >Transactions and auto-commit - Manual - PHP
Auto-commit mode means that every query that you run has its own implicit transaction, if the database supports it, or no transaction if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In my case the problem was a stupid mistake - missing
await
when calling thesave
This feature is desperately needed for code quality purposes and to ease the pain of testing with Sequelize at the moment.
@roytz, from everything I could find, the prescribed way to use transactions is to perform all of the operations you need to do from within the context of the next handler in the promise chain like so:
Which I find fairly annoying to deal with.