Skip to main content
Version: v6 - stable

乐观锁

Sequelize 通过模型实例版本计数内置支持乐观锁定。

¥Sequelize has built-in support for optimistic locking through a model instance version count.

乐观锁定默认处于禁用状态,可以通过在特定模型定义或全局模型配置中将 version 属性设置为 true 来启用。详细信息请参见 型号配置

¥Optimistic locking is disabled by default and can be enabled by setting the version property to true in a specific model definition or global model configuration. See model configuration for more details.

乐观锁定允许并发访问模型记录进行编辑,并防止覆盖数据的冲突。它通过检查自读取记录以来另一个进程是否对记录进行了更改来实现此目的,并在检测到冲突时抛出 OptimisticLockError。

¥Optimistic locking allows concurrent access to model records for edits and prevents conflicts from overwriting data. It does this by checking whether another process has made changes to a record since it was read and throws an OptimisticLockError when a conflict is detected.