Unmanaged transaction (then-callback)

Unmanaged transactions force you to manually rollback or commit the transaction. If you don't do that, the transaction will hang until it times out. To start an unmanaged transaction, call sequelize.transaction() without a callback (you can still pass an options object) and call then on the returned promise. Notice that commit() and rollback() returns a promise.

  1. return sequelize.transaction().then(t => {
  2. return User.create({
  3. firstName: 'Bart',
  4. lastName: 'Simpson'
  5. }, {transaction: t}).then(user => {
  6. return user.addSibling({
  7. firstName: 'Lisa',
  8. lastName: 'Simpson'
  9. }, {transaction: t});
  10. }).then(() => {
  11. return t.commit();
  12. }).catch((err) => {
  13. return t.rollback();
  14. });
  15. });