Class: Turso::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/turso/transaction.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, mode = :immediate) ⇒ Transaction

Returns a new instance of Transaction.



7
8
9
10
11
12
13
14
# File 'lib/turso/transaction.rb', line 7

def initialize(db, mode = :immediate)
  unless VALID_TRANSACTION_MODES.include?(mode)
    fail ArgumentError, "Invalid transaction mode: #{mode.inspect}. Valid modes: #{VALID_TRANSACTION_MODES.inspect}"
  end
  @db = db
  @mode = mode
  @active = false
end

Instance Method Details

#beginObject



16
17
18
19
# File 'lib/turso/transaction.rb', line 16

def begin
  @db.execute("BEGIN #{@mode.to_s.upcase}")
  @active = true
end

#commitObject



21
22
23
24
# File 'lib/turso/transaction.rb', line 21

def commit
  @db.execute("COMMIT")
  @active = false
end

#rollbackObject



26
27
28
29
# File 'lib/turso/transaction.rb', line 26

def rollback
  @db.execute("ROLLBACK")
  @active = false
end