Class: Turso::Transaction
- Inherits:
-
Object
- Object
- Turso::Transaction
- Defined in:
- lib/turso/transaction.rb
Instance Method Summary collapse
- #begin ⇒ Object
- #commit ⇒ Object
-
#initialize(db, mode = :immediate) ⇒ Transaction
constructor
A new instance of Transaction.
- #rollback ⇒ Object
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
#begin ⇒ Object
16 17 18 19 |
# File 'lib/turso/transaction.rb', line 16 def begin @db.execute("BEGIN #{@mode.to_s.upcase}") @active = true end |
#commit ⇒ Object
21 22 23 24 |
# File 'lib/turso/transaction.rb', line 21 def commit @db.execute("COMMIT") @active = false end |
#rollback ⇒ Object
26 27 28 29 |
# File 'lib/turso/transaction.rb', line 26 def rollback @db.execute("ROLLBACK") @active = false end |