How to use the machinepack-postgresql.commitTransaction function in machinepack-postgresql

To help you get started, we’ve selected a few machinepack-postgresql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balderdashy / sails-postgresql / helpers / private / connection / commit-and-release.js View on Github external
module.exports = function commitAndRelease(connection, leased, cb) {
  if (!connection || _.isFunction(connection)) {
    return cb(new Error('Commit and Release requires a valid connection.'));
  }

  // Commit the transaction
  PG.commitTransaction({
    connection: connection
  })
  .exec(function commitCb(err) {
    if (err) {
      // Rollback the transaction
      PG.rollbackTransaction({
        connection: connection
      })
      .exec(function rollbackCb() {
        // Only release the connection if it wasn't leased from outside the
        // adapter.
        if (leased) {
          return cb(err);
        }

        // Release the connection back into the pool