async function runInTransaction (f) {

  let dbClient = this

  try {
    await dbClient.query('BEGIN;')

    let retval = await f(dbClient)

    await dbClient.query('COMMIT;')

    return retval

  } catch (e) {//always rollback on exception if the transaction was opened
    if(dbClient) {
      try {
        await dbClient.query('ROLLBACK;')//rollback any work that hasn't been committed.
      } catch (e) { //there's no helpful way to notify the user of the inner exception
        console.error(caughtException)
      }
    }

    throw e //and rethrow the exception
  }
}
/**
 *  * runs a function inside of a transaction and commits unless an exception is throw.  After resolving the transaction it passes back either the return value or the exception
 *   */
runs a function inside of a transaction and commits unless an exception is throw.  After resolving the transaction it passes back either the return value or the exception
runs a function inside of a transaction and commits unless an exception is throw . After resolving the transaction it passes back either the return value or the exception
async function runInTransaction (f) {
  let dbClient = this
  try {
    await dbClient.query('BEGIN;')
    let retval = await f(dbClient)
    await dbClient.query('COMMIT;')
    return retval
  } catch (e) {
    if(dbClient) {
      try {
        await dbClient.query('ROLLBACK;')
      } catch (e) { 
        console.error(caughtException)
      }
    }
    throw e 
  }
}
async function runInTransaction ( f ) { let dbClient = this try { await dbClient . query ( 'BEGIN;' ) let retval = await f ( dbClient ) await dbClient . query ( 'COMMIT;' ) return retval } catch ( e ) { if ( dbClient ) { try { await dbClient . query ( 'ROLLBACK;' ) } catch ( e ) { console . error ( caughtException ) } } throw e } }
* runs a function inside of a transaction and commits unless an exception is throw.
* runs a function inside of a transaction and commits unless an exception is throw .
//always rollback on exception if the transaction was opened //rollback any work that hasn't been committed. //there's no helpful way to notify the user of the inner exception //and rethrow the exception