2.1.1 • Published 5 years ago

pg-async-transaction v2.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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

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

2.1.1

5 years ago

2.1.0

7 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.4

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago