Skip to content

Instantly share code, notes, and snippets.

@phongkt-dev
Last active June 11, 2019 10:35
Show Gist options
  • Select an option

  • Save phongkt-dev/94c819438b96a9e0439d35d725c95483 to your computer and use it in GitHub Desktop.

Select an option

Save phongkt-dev/94c819438b96a9e0439d35d725c95483 to your computer and use it in GitHub Desktop.
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