Implement `transaction.end()`
surprisetalk opened this issue · comments
The following example is listed in the official docs:
const transaction = client.createTransaction(
"partially_rolled_back_transaction",
);
await transaction.savepoint("undo");
await transaction.queryArray`TRUNCATE TABLE DONT_DELETE_ME`; // Oops, wrong table
await transaction.rollback("undo"); // Truncate is rolled back, transaction continues
await transaction.end();
It's in the docs, but doesn't seem to exist in the code.
Without .end()
, we can't reuse connections, which is pretty important for many applications:
const client = await pool.connect();
while (true) {
const tx = client.createTransaction(`example-tx`);
tx.queryArray(`...`);
await tx.commit();
await tx.end(); // doesn't exist
n++;
}
If the intended design is to reconnect to the pool, maybe we should update the docs?
There is indeed a mistake in the docs making a mention of an end method which doesn't exist, however you don't need to look for a close method in order to close a transaction
The commit
method will take care of closing the transaction and releasing the client per https://doc.deno.land/https://deno.land/x/postgres@v0.15.0/mod.ts/~/Transaction#commit and the docs (unless the commit is specified to be chained)
I'll close this issue once the docs are updated to remove references to the close
method