-
-
Notifications
You must be signed in to change notification settings - Fork 619
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
Added .transaction(options ?,asyncFunction) to PromisePool & PromiseConnection #811
Conversation
let me think about this :) I'm trying to resist adding more functionality to pool but it actually looks useful Couple of notes: const xyz = await promise.withConnection(async conn => {
await conn.beginTransaction();
const [rows] = await conn.query('insert .,,,');
await conn.commit();
return rows[0].someAutoIncrementField;
}); also - maybe "withTransaction" that does .rollback() + .release in catch block? For individual unrelated queries there is no benefit of Definitely needs unit tests to move forward |
Perhaps this would be better to model after the .transaction() call in the sequelize module. http://docs.sequelizejs.com/manual/tutorial/transactions.html A .transaction() with no isolation, in auto commit mode, with no rollback, would essentially have the same behavior as .withConnection(), except the developer would have to choose that mode explicitly. It’s probably a good thing to force the developer to choose an isolation level. |
I changed .withConnection() to .transaction(), and added behavior to run queries under different types of transactions. I haven't tried this code yet, it is completely untested. The previous behavior of .withConnection() is now available by calling .transaction({ autoCommit: true }) |
…ransactions now work on Pools and Connections
…ariables to make them const-correct
…rror if a Query is used as if it is a promise.
Could you extract ping() and When new api methods I'd like PRs to stay open a bit longer with more eyes, once it's in it's really difficult to go back without potentially breaking someone's code |
This PR adds a .withConnection(asyncFunction) function to PromisePool, which allows the user to borrow a connection from the connection pool, run as many queries as they like, and then it will automatically release the connection back to the pool when the asyncFunction(con) they pass in either resolves or rejects.
Solves a garbage disposal problem when using promise pools.