How to use the machinepack-postgresql.rollbackTransaction 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
.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
        PG.releaseConnection({
          connection: connection
        })
        .exec(function releaseCb() {
          return cb(err);
        });
github balderdashy / sails-postgresql / helpers / private / connection / rollback-and-release.js View on Github external
module.exports = function rollbackAndRelease(connection, leased, cb) {
  if (!connection || _.isFunction(connection)) {
    return cb(new Error('Commit and Release requires a valid connection.'));
  }

  // Rollback the transaction
  PG.rollbackTransaction({
    connection: connection
  })
  .exec(function rollbackCb() {
    // Only release the connection if the leased flag is false
    if (leased) {
      return cb();
    }

    // Release the connection back into the pool
    PG.releaseConnection({
      connection: connection
    })
    .exec(function releaseCb() {
      return cb();
    });
  });