How to use the machinepack-postgresql.beginTransaction 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 / begin-transaction.js View on Github external
module.exports = function beginTransaction(connection, leased, cb) {
  PG.beginTransaction({
    connection: connection
  })
  .exec({
    // If there was an error opening a transaction, release the connection.
    // After releasing the connection always return the original error.
    error: function error(err) {
      // If the connection was leased from outside the adapter, don't release it.
      if (leased) {
        return cb(new Error('There was an error starting a transaction. ' + err.stack));
      }

      PG.releaseConnection({
        connection: connection
      }).exec({
        error: function error(err) {
          return cb(new Error('There was an error releasing the connection back into the pool. ' + err.stack));