Make it easier to write transactions for PostgreSQL using node-postgres.
The callback and event emitter styles both work.
Note: if you use a callback, then the error event won't be emitted. This is consistent with node-postgres.
Installation:
To install the most recent release from npm, run:
npm install pg-transaction
Methods:
;; // This is pg.Client.query from node-postgres. There are various possible arguments look at its documentation;;;;;
Events:
- error
Example:
/** * Module dependencies */ var // PostgreSQL modules pg = Transaction = // Configuration stuff connectionString = processenv'PG_CON' || ''; var { if err throw err;}; var client = connectionString;client; client; var tx = client;tx; tx;tx;tx;tx;tx; // all statements after savepoint1 are undone (John will not be inserted)tx; // can no longer use savepoint1 as a point to rollback totx; client;