pg-transaction v1.0.4 is a small Node.js library that simplifies PostgreSQL transaction management on top of node-postgres (pg). It wraps pg.Client with a Transaction object supporting begin, commit, rollback, savepoints, and release. The library uses either callbacks or event emitters for error handling. Released in 2013 and last updated in 2014, it is considered stable but unmaintained. Key differentiator: provides a simple abstraction over raw BEGIN/COMMIT/ROLLBACK SQL, working exclusively with node-postgres.
npm install pg-transactionNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a PostgreSQL client, wraps it in a Transaction, executes a transaction with savepoint and rollback.
Use either callbacks entirely or events entirely, not both.
Consider alternatives like pg-promise or knex transactions for modern applications.
Ensure client.connect() callback has succeeded before creating a Transaction.
Always rollback before release if you intend to undo changes at a savepoint.
Change to const Transaction = require('pg-transaction');Ensure tx.savepoint('sp1') is called before release or rollback, and don't release twice.Always call tx.commit() or tx.rollback() before starting a new transaction on the same tx object.