Closed
Description
Is your feature request related to a problem? Please describe.
Deno already supports using
and await using
syntax with some APIs
Describe the solution you'd like
Instead of this:
{
const client = await pgPool.connect();
try {
// ... await some work
} finally {
client.release()
}
}
I wish write this:
{
using client = await pgPool.connect();
// ... await some work
} // client is released automatically
In addition, second step
Similar syntax can be used for transactions too, for example:
{
using client = await pgPool.connect();
await using transaction = await client.begin();
await transaction.queryArray(...);
await transaction.commit(); // otherwise it will rollback
}
// - automatically rollback transaction if not commited and
// report, that transaction was not properly closed (either commited or rolled back)
// - release client
Advanced example:
{
using client = await pgPool.connect();
try {
await using transaction = await client.begin();
await transaction.queryArray(...);
if (somethingBadHappened) {
await transaction.rollback();
}
await transaction.commit();
}
// automatically rollback transaction if not commited and
// report, that transaction was not properly closed (either commited or rolled back)
catch(error)
{
// transaction is rolled back
console.log(error);
}
} // release client
Metadata
Metadata
Assignees
Labels
No labels