Module: Surus::SynchronousCommit::Connection

Defined in:
lib/surus/synchronous_commit/connection.rb

Instance Method Summary collapse

Instance Method Details

#synchronous_commit(value = :not_passed_param) ⇒ Object

When called without any value returns the current synchronous_commit value.

When called with a value it is delegated to #synchronous_commit=



8
9
10
11
12
13
14
# File 'lib/surus/synchronous_commit/connection.rb', line 8

def synchronous_commit(value=:not_passed_param)
  if value == :not_passed_param
    select_value("SHOW synchronous_commit") == "on"
  else
    self.synchronous_commit = value
  end
end

#synchronous_commit=(value) ⇒ Object

Changes current synchronous_commit state. If a transaction is currently in progress the change will be reverted at the end of the transaction.

Requires true or false to be passed exactly – not merely truthy or falsy

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/surus/synchronous_commit/connection.rb', line 20

def synchronous_commit=(value)
  raise ArgumentError, "argument must be true or false" unless value == true || value == false

  execute "SET #{'LOCAL' if open_transactions > 0} synchronous_commit TO #{value ? 'ON' : 'OFF'}"
end