rollback
The rollback method explicitly discards the staged transaction.
rollback(): Promise<void>Example
import {create} from 'tinyjoin';
const db = await create();
await db.exec(`
CREATE TABLE tasks (id TEXT PRIMARY KEY, title TEXT NOT NULL)
`);
await db.transaction(async (tx) => {
await tx.query('INSERT INTO tasks (id, title) VALUES ($1, $2)', [
'a',
'Write docs',
]);
await tx.rollback();
console.log(tx.closed);
// -> true
});
const {rows} = await db.query('SELECT * FROM tasks');
console.log(rows);
// -> []
await db.close();