title: node-postgres transactions with callbacks or async/await?
body: <p>I'm running Node 7.6.0, which supports async/await. The node-postgres client pool supports async/await, and has a nice example <a href="https://github.com/brianc/node-pg-pool#plays-nice-with-asyncawait" rel="noreferrer">here</a>. However, the example for transactions in node-postgres (<a href="https://github.com/brianc/node-postgres/wiki/Transactions" rel="noreferrer">here</a>) uses callbacks instead of async/await. Despite that example, I thought I'd try transactions with async/await in a quick test:</p>
  
  <pre><code>let client = null;
  
  try {
      client = await this.pool.connect();
  } catch (error) {
      console.log('A client pool error occurred:', error);
      return error;
  }
  
  try {
      await client.query('BEGIN');
      await client.query('UPDATE foo SET bar = 1');
      await client.query('UPDATE bar SET foo = 2');
      await client.query('COMMIT');
  } catch (error) {
      try {
          await client.query('ROLLBACK');
      } catch (rollbackError) {
          console.log('A rollback error occurred:', rollbackError);
      }
      console.log('An error occurred:', error);
      return error;
  } finally {
      client.release();
  }
  
  return 'Success!';
  </code></pre>
  
  <p>This seems to work just fine, but <a href="https://github.com/brianc/node-postgres/issues/1252" rel="noreferrer">I was told</a> by a node-postgres contributor that this is a bad idea. Unfortunately, he didn't take the time to explain <em>why</em> this is a bad idea—he just said to seek an answer on Stack Overflow.</p>
  
  <p>Why is it a bad idea to perform transactions with async/await instead of callbacks in node-postgres?</p>