index.js
function performTransaction(pool, queries, callback) {
  pool.connect((error, client, done) => {
    if (error) {
      done(client);
      return callback(error, null);
    }

    client.query('BEGIN', error => {
      if (error) {
        return rollback(client, done, error, callback);
      }

      sequence(queries, (results, current, next) => {
        let query  = current.text,
            params = current.values;

        client.query(query, params, (error, result) => {
          if (error) {
            return rollback(client, done, error, callback);
          }

          results.push(result);
          next();
        });
      }, (results) => {
        client.query('COMMIT', error => {
          if (error) {
            return rollback(client, done, error, callback);
          }

          done(client);
          return callback(null, results);
        });
      });
    });
  });
}
function performTransaction(pool, queries, callback) {
  pool.connect((error, client, done) => {
    if (error) {
      done(client);
      return callback(error, null);
    }

    client.query('BEGIN', error => {
      if (error) {
        return rollback(client, done, error, callback);
      }

      sequence(queries, (results, current, next) => {
        let query  = current.text,
            params = current.values;

        client.query(query, params, (error, result) => {
          if (error) {
            return rollback(client, done, error, callback);
          }

          results.push(result);
          next();
        });
      }, (results) => {
        client.query('COMMIT', error => {
          if (error) {
            return rollback(client, done, error, callback);
          }

          done(client);
          return callback(null, results);
        });
      });
    });
  });
}
function performTransaction ( pool , queries , callback ) { pool . connect ( ( error , client , done ) => { if ( error ) { done ( client ) ; return callback ( error , null ) ; } client . query ( 'BEGIN' , error => { if ( error ) { return rollback ( client , done , error , callback ) ; } sequence ( queries , ( results , current , next ) => { let query = current . text , params = current . values ; client . query ( query , params , ( error , result ) => { if ( error ) { return rollback ( client , done , error , callback ) ; } results . push ( result ) ; next ( ) ; } ) ; } , ( results ) => { client . query ( 'COMMIT' , error => { if ( error ) { return rollback ( client , done , error , callback ) ; } done ( client ) ; return callback ( null , results ) ; } ) ; } ) ; } ) ; } ) ; }
Using the specified connection pool, performs a series of specified queries
using any specified parameters in sequence, finally executing a specified
callback function with any error or result. Will automatically rollback the
transaction if it fails and commit if it succeeds.
@param  {BoundPool}      pool
@param  {Array.<Object>} queries
@param  {Function}       callback
@private
Using the specified connection pool performs a series of specified queries using any specified parameters in sequence finally executing a specified callback function with any error or result . Will automatically rollback the transaction if it fails and commit if it succeeds .