Module | Sequel::Plugins::OptimisticLocking
In: | lib/sequel/plugins/optimistic_locking.rb

This plugin implements a simple database-independent locking mechanism to ensure that concurrent updates do not override changes. This is best implemented by a code example:

      class Person < Sequel::Model
        plugin :optimistic_locking
      end
      p1 = Person[1]
      p2 = Person[1]
      p1.update(:name=>'Jim') # works
      p2.update(:name=>'Bob') # raises Sequel::Plugins::OptimisticLocking::Error

In order for this plugin to work, you need to make sure that the database table has a lock_version column (or other column you name via the lock_column class level accessor) that defaults to 0.

This plugin relies on the instance_filters plugin.

### Methods

apply configure

### Classes and Modules

Module Sequel::Plugins::OptimisticLocking::ClassMethods
Module Sequel::Plugins::OptimisticLocking::InstanceMethods

### Constants

Error | = | InstanceFilters::Error |  | Exception class raised when trying to update or destroy a stale object.

### Public Class methods

apply(model, opts={})

Load the instance_filters plugin into the model.

[Source]

        # File lib/sequel/plugins/optimistic_locking.rb, line 27
    27:       def self.apply(model, opts={})
    28:         model.plugin :instance_filters
    29:       end

configure(model, opts={})

Set the lock_column to the :lock_column option, or :lock_version if that option is not given.

[Source]

        # File lib/sequel/plugins/optimistic_locking.rb, line 33
    33:       def self.configure(model, opts={})
    34:         model.lock_column = opts[:lock_column] || :lock_version
    35:       end

[Validate]