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. |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.