Method: Baza::Driver::ActiveRecord#transaction

Defined in:
lib/baza/driver/active_record.rb

#transactionObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/baza/driver/active_record.rb', line 120

def transaction
  if @driver_type == :mysql || @driver_type == :mysql2 || @driver_type == :pg
    query("START TRANSACTION")
  elsif @driver_type == :sqlite3
    query("BEGIN TRANSACTION")
  else
    raise "Don't know how to start transaction"
  end

  begin
    yield @db
    query("COMMIT")
  rescue
    query("ROLLBACK")
    raise
  end
end