# pg-transact

> A nicer API on node-postgres transactions

Latest version **1.0.1** (published 2014-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install pg-transact
pnpm add pg-transact
yarn add pg-transact
bun add pg-transact
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-11-04 |
| First published | 2014-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Blaine Bublitz |
| Maintainers | phated |
| Keywords | pg, postgres, transactions, tx |

## Links

- npm: https://www.npmjs.com/package/pg-transact
- Repository: https://github.com/iceddev/pg-transact
- Issues: https://github.com/iceddev/pg-transact/issues
- npm.io page: https://npm.io/package/pg-transact

## Dependencies (1)

- [when](https://npm.io/package/when.md) ^3.5.2

## Recent versions

- 1.0.1 (latest) — 2014-11-04
- 1.0.0 — 2014-10-31

## README

pg-transact
===========

[![Build Status](https://travis-ci.org/iceddev/pg-transact.svg?branch=master)](https://travis-ci.org/iceddev/pg-transact)

A nicer API on node-postgres transactions

## Usage

```js
var pg = require('pg.js');
var pgTransact = require('pg-transact');

function transaction(client, cb){
  // everything in here is run as a transaction
  client.query('SELECT NOW() as when', function(err, result){
    if(err){
      // passing an error to the callback does a rollback on the transaction
      return cb(err);
    }

    // passing a `null` error and a result will resolve the transaction as the result
    cb(null, result);
  });
}

pg.connect(connectionString, function(err, client, done){
  if(err){
    throw err;
  }

  pgTransact(client, transaction, done)
    .then(console.log, console.error);
});
```

It also will work with a returned promise:

```js
var pg = require('pg.js');
var pgTransact = require('pg-transact');

function transaction(client, cb){
  return new Promise(function(resolve, reject){
    client.query('SELECT NOW() as when', function(err, result){
      if(err){
        return reject(err);
      }

      resolve(result);
    });
  });
}

pg.connect(connectionString, function(err, client, done){
  if(err){
    throw err;
  }

  pgTransact(client, transaction, done)
    .then(console.log, console.error);
});
```

---
_Source: https://npm.io/package/pg-transact · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
