Transaction on pool connection #44
|
Hello! I wanted to use a transaction on my project, but I use a Pool connection. I saw that a transaction is not possible on the Pool connection, but in the PoolConfiguration interface, which extends the basic Connection, you can pass the autoCommit property to false. But given that you can only use a transaction from the basic connection method, why use the same interface and not another? Or we could use a transaction on the Pool connection but I'm doing it wrong. |
Answered by
erayhanoglu
Nov 26, 2024
Replies: 1 comment
|
You can use transaction with pool. const result = await dbpool.acquire((connection)=>{
await connection.startTransaction();
// Do what ever you want.
);Transaction will be committed on successful execution of the arrow function. If any error occurs, transaction will be rolled back automatically. Alternatively you can call connection.commit() or connection.rollback() any time. |
0 replies
Answer selected by
erayhanoglu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use transaction with pool.
Transaction will be committed on successful execution of the arrow function. If any error occurs, transaction will be rolled back automatically. Alternatively you can call connection.commit() or connection.rollback() any time.