# pg-async-transaction

> Trivially wraps `BEGIN` and `COMMIT` to provide behind-the-scenes transaction support for your POSTGRES queries.

Latest version **2.1.1** (published 2018-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install pg-async-transaction
pnpm add pg-async-transaction
yarn add pg-async-transaction
bun add pg-async-transaction
```

## 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 | 2.1.1 |
| Published | 2018-12-11 |
| First published | 2016-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel Cousens |
| Maintainers | dcousens |
| Keywords | async, parallel, queries, postgres, transaction |

## Links

- npm: https://www.npmjs.com/package/pg-async-transaction
- Repository: https://github.com/dcousens/pg-async-transaction
- Homepage: https://github.com/dcousens/pg-async-transaction#readme
- Issues: https://github.com/dcousens/pg-async-transaction/issues
- npm.io page: https://npm.io/package/pg-async-transaction

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2018-12-11
- 2.1.0 — 2016-12-07
- 2.0.1 — 2016-09-15
- 2.0.0 — 2016-09-15
- 1.0.4 — 2016-09-15
- 1.0.2 — 2016-09-15
- 1.0.1 — 2016-09-15

## README

# pg-async-transaction
Trivially wraps `BEGIN` and `COMMIT` to provide behind-the-scenes transaction support for your POSTGRES queries.

If `callback(err)` happens,  the wrapper calls `ROLLBACK` and upon success returns the `err` object.

If `ROLLBACK` errors, preference is given to the `ROLLBACK` error in the spot of `err`.


## Example
``` js
const pg = require('pg')
const pat = require('pg-async-transaction')
const parallel = require('run-parallel')

function foo (done) {
  pg.connect(process.env.POSTGRES, (err, client, free) => {
    if (err) return done(err)

    pat(client, (callback) => {
      parallel([
        (next) => client.query('INSERT ...', next),
        (next) => client.query('INSERT ...', next),
        (next) => client.query('INSERT ...', next)
      ], callback)
    }, (err, results) => {
      if (err) free()

      free()
      done(err)
    })
  })
}

// ...
```

## LICENSE [MIT](LICENSE)

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