Advertisement
orkhanhuseynli

SALAAAAAM

Oct 14th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // First, we start a transaction from your connection and save it into a variable
  2. const t = await sequelize.transaction();
  3.  
  4. try {
  5. // Then, we do some calls passing this transaction as an option:
  6.  
  7. const user = await User.create(
  8. {
  9. firstName: 'Bart',
  10. lastName: 'Simpson',
  11. },
  12. { transaction: t },
  13. );
  14.  
  15. await user.addSibling(
  16. {
  17. firstName: 'Lisa',
  18. lastName: 'Simpson',
  19. },
  20. { transaction: t },
  21. );
  22.  
  23. // If the execution reaches this line, no errors were thrown.
  24. // We commit the transaction.
  25. await t.commit();
  26. } catch (error) {
  27. // If the execution reaches this line, an error was thrown.
  28. // We rollback the transaction.
  29. await t.rollback();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement