Confusion about transaction code:
See original GitHub issueMy transaction code:
try {
const cn = await pool.getConnection()
await cn.beginTransaction()
await cn.execute(' ...
await cn.execute(' ...
await cn.commit()
}
catch {
await cn.rollback()
}
But am I wrong? Should it be:
const cn = await pool.getConnection()
try {
await cn.beginTransaction()
await cn.execute(' ...
await cn.execute(' ...
await cn.commit()
}
catch {
await cn.rollback()
}
But wait! Should it be?
const cn = await pool.getConnection()
await cn.beginTransaction()
try {
await cn.execute(' ...
await cn.execute(' ...
await cn.commit()
}
catch {
await cn.rollback()
}
I’m afraid I don’t know the answer. Thanks in advance anyone who can advise. (It may help others also?)
Issue Analytics
- State:
- Created a year ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Chargeback Reason Codes: The Ultimate Guide
However, the process can still cause a lot of confusion, especially at the merchant level, where there's no insight into the process of...
Read more >Confusion in transactions · Issue #97 · simolus3/drift - GitHub
We call the transaction callback in a new Zone . Whenever a method is called on the database class, we will check if...
Read more >Confusion about finding customer exit - SAP Community
I am sorry but I have a trivial issue that I am confused about. ... I came across a requirement to find customer...
Read more >Transactions and Isolation Level Confusion - Ask TOM
Hi, Tom. I have some questions about transactions and isolation levels that come from my reading of your books and answers in this...
Read more >SAP PRESS - T-codes can be confusing. Cut through the...
T-codes can be confusing. Cut through the confusion with our reference guide to transaction codes in SAP ERP. https://hubs.la/H0CqGz60.
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
there was a discussion somewhere here about possible better helper api that would handle this pattern, for example something similar to https://github.com/porsager/postgres#transactions ( I’ve started some initial work here )
beginTransaction / commit / rollback are just simple helpers to perform
START TRANSACTION
/COMMIT
/ROLLBACK
queriesTo me 3rd example is the most correct but I’m not an SQL / mysql expert
Possible reasons why
pool.getConnection()
can fail: network error in the process of getting a new connection, too many connections limit reached (server side), client side limit on number of open connectionsNot sure when
START TRANSACTION
can fail ( reasons other than connection is killed because of network error or other clientKILL thread_id
) but I guess rollback only makes sense after successfulSTART TRANSACTION