Method: ROM::SQL::Relation::Reading#lock

Defined in:
lib/rom/sql/relation/reading.rb

#lock(options) ⇒ SQL::Relation #lock(options) {|relation| ... } ⇒ Object

Lock rows with in the specified mode. Check out ROW_LOCK_MODES for the list of supported modes, keep in mind available lock modes heavily depend on the database type+version you’re running on.

Overloads:

  • #lock(options) ⇒ SQL::Relation

    Options Hash (options):

    • :mode (Symbol)

      Lock mode

    • :wait (Boolean, Integer)

      Controls the (NO)WAIT part

    • :skip_locked (Boolean)

      Skip locked rows

    • :of (Array, Symbol, String)

      List of objects in the OF part

    Returns:

  • #lock(options) {|relation| ... } ⇒ Object

    Runs the block inside a transaction. The relation will be materialized and passed inside the block so that the lock will be acquired right before the block gets executed.

    Parameters:

    • options (Hash)

      The same options as for the version without a block

    Yield Parameters:

    • relation (Array)


913
914
915
916
917
918
919
920
921
922
923
# File 'lib/rom/sql/relation/reading.rb', line 913

def lock(**options, &)
  clause = lock_clause(**options)

  if block_given?
    transaction do
      yield(dataset.lock_style(clause).to_a)
    end
  else
    new(dataset.lock_style(clause))
  end
end