title: node js. Sequelize transactions
body: <p>I have 'Banks' table with 'money' field in my database,</p>
  
  <p>Users can withdraw money periodically, but they can withdraw only if there is money > 0 in the bank.</p>
  
  <p>Firstly I should get the entity of bank, then check if(bank.money > amountToWithdraw) and then withdraw this amount.</p>
  
  <p>Imagine the situation, when concurrent user try to withdraw some money.
  In that moment when I check if(bank.money > amountToWithdraw) other user can perform withdraw operation and the real bank.money amount in the DB will be less.</p>
  
  <p>How to apply transaction to finding bank operation(how to lock bank entity)?</p>
  
  <pre><code>models.sequelize.transaction(function (t) {
  
  return models.Banks.findOne({where: {
      money: {
        $gt: 0
      }
    }).then(function(bank){
  
      //in this moment other user finished the same operation
  // how to lock access for editing bank object by other users after //findOne method?
  
      bank.money -= amountToWithdraw;
      return bank.save({transaction: t});
    })
  })
  </code></pre>