title: Knex Transaction with Promises
body: <p>I am getting the correct output, and indeed, these two operations are being treated as a single transactional unit; where if one fails, both fail.</p>
  
  <p>In this code example: i am doing a transaction of</p>
  
  <p>(1) insert
  (2) update</p>
  
  <p>The way I approach it is to nest my db operations inside the .then.
  My question is if this code is correct by accident? i am new to promises and knex.</p>
  
  <pre><code>knex.transaction(function(t) {
     knex('foo')
     .transacting(t)
     .insert({id:"asdfk", username:"barry", email:"barry@bar.com"})
     .then(function() {
         knex('foo')
         .where('username','=','bob')
         .update({email:"bob@foo.com"})
         .then(t.commit, t.rollback)
     })
  })
  .then(function() {
   // it worked
  },
  function() {
   // it failed
  });
  </code></pre>
  
  <p>This works, but I feel like I am doing something wrong still. Looking for comments.</p>