Class: Turso::Database
- Inherits:
-
Object
- Object
- Turso::Database
- Extended by:
- Forwardable
- Defined in:
- lib/turso/database.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #connection ⇒ Object
-
#initialize(path = ":memory:", **options) ⇒ Database
constructor
A new instance of Database.
- #transaction(mode = :deferred) ⇒ Object
Constructor Details
#initialize(path = ":memory:", **options) ⇒ Database
Returns a new instance of Database.
14 15 16 17 18 |
# File 'lib/turso/database.rb', line 14 def initialize(path = ":memory:", **) [:experimental_features] = normalize_experimental_features([:experimental_features]) @native = NativeDatabase.new(path, ) @closed = false end |
Instance Method Details
#close ⇒ Object
34 35 36 37 38 |
# File 'lib/turso/database.rb', line 34 def close return if closed? @native.close @closed = true end |
#closed? ⇒ Boolean
30 31 32 |
# File 'lib/turso/database.rb', line 30 def closed? @closed || !@native.open? end |
#connection ⇒ Object
40 41 42 |
# File 'lib/turso/database.rb', line 40 def connection Connection.new(@native.connection) end |
#transaction(mode = :deferred) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/turso/database.rb', line 44 def transaction(mode = :deferred) raise Turso::Exception, "database is closed" if closed? execute("BEGIN #{mode.to_s.upcase}") begin result = yield self execute("COMMIT") result rescue ::Exception execute("ROLLBACK") raise end end |