Method: MDBX::Database#transaction

Defined in:
lib/mdbx/database.rb

#transaction(commit: true, &block) ⇒ Object

Open a new mdbx read/write transaction. In block form, the transaction is automatically committed when the block ends.

Raising a MDBX::Rollback exception from within the block automatically rolls the transaction back.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/mdbx/database.rb', line 177

def transaction( commit: true, &block )
  self.open_transaction( commit )
  yield self if block_given?

  return self

rescue MDBX::Rollback
  commit = false
  self.rollback
rescue
  commit = false
  self.rollback
  raise
ensure
  if block_given?
    commit ? self.commit : self.rollback
  end
end