不要怂,就是干,撸起袖子干!

You need to sign in or sign up before continuing.
transaction.md 2.98 KB

Class Transaction

View code The transaction object is used to identify a running transaction. It is created by calling Sequelize.transaction().

To run a query under a transaction, you should pass the transaction in the options object.

Params:

Name Type Description
sequelize Sequelize A configured sequelize Instance
options Object An object with options
options.autocommit=true Boolean Sets the autocommit property of the transaction.
options.isolationLevel=true String Sets the isolation level of the transaction.
options.deferrable String Sets the constraints to be deferred or immediately checked.

ISOLATION_LEVELS

View code The possible isolations levels to use when starting a transaction. Can be set per-transaction by passing options.isolationLevel to sequelize.transaction. Default to REPEATABLE_READ but you can override the default isolation level by passing options.isolationLevel in new Sequelize.

{
  READ_UNCOMMITTED: "READ UNCOMMITTED",
  READ_COMMITTED: "READ COMMITTED",
  REPEATABLE_READ: "REPEATABLE READ",
  SERIALIZABLE: "SERIALIZABLE"
}

LOCK

View code Possible options for row locking. Used in conjuction with find calls:

t1 // is a transaction
t1.LOCK.UPDATE,
t1.LOCK.SHARE,
t1.LOCK.KEY_SHARE, // Postgres 9.3+ only
t1.LOCK.NO_KEY_UPDATE // Postgres 9.3+ only

Usage:

t1 // is a transaction
Model.findAll({
  where: ...,
  transaction: t1,
  lock: t1.LOCK...
});

Postgres also supports specific locks while eager loading by using OF:

UserModel.findAll({
  where: ...,
  include: [TaskModel, ...],
  transaction: t1,
  lock: {
    level: t1.LOCK...,
    of: UserModel
  }
});

UserModel will be locked but TaskModel won't!


commit() -> this

View code Commit the transaction


rollback() -> this

View code Rollback (abort) the transaction


This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on IRC, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see JSDoc and dox