Class: Turso::Database

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/turso/database.rb

Instance Method Summary collapse

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:", **options)
  options[:experimental_features] = normalize_experimental_features(options[:experimental_features])
  @native = NativeDatabase.new(path, options)
  @closed = false
end

Instance Method Details

#closeObject



34
35
36
37
38
# File 'lib/turso/database.rb', line 34

def close
  return if closed?
  @native.close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/turso/database.rb', line 30

def closed?
  @closed || !@native.open?
end

#connectionObject



40
41
42
# File 'lib/turso/database.rb', line 40

def connection
  Connection.new(@native.connection)
end

#transaction(mode = :deferred) ⇒ Object

Raises:

  • (Turso::Exception)


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