Last active
June 11, 2019 10:35
-
-
Save phongkt-dev/94c819438b96a9e0439d35d725c95483 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let transaction | |
| try { | |
| // Unmanaged Transaction | |
| transaction = await sequelize.transaction() | |
| // make sure to use the transaction in options | |
| await MyModel.create({ key: "some-value" }, { transaction }) | |
| // always call commit at the end | |
| await transaction.commit() | |
| } catch (err) { | |
| // always rollback | |
| await transaction.rollback() | |
| } | |
| if (transaction.finished === 'commit') { | |
| // The transaction has been commit! | |
| // You can check for transaction status right here! | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment