Class: Libsql::Database
- Inherits:
-
Object
- Object
- Libsql::Database
- Defined in:
- lib/libsql.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #connect ⇒ Object
-
#initialize(options = {}) ⇒ Database
constructor
A new instance of Database.
- #sync ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Database
Returns a new instance of Database.
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/libsql.rb', line 548 def initialize( = {}) desc = CLibsql::DatabaseDesc.new %i[path url auth_token encryption_key].each do |sym| desc[sym] = FFI::MemoryPointer.from_string [sym] unless [sym].nil? end desc[:sync_interval] = [:sync_interval] || 0 desc[:disable_read_your_writes] = ![:read_your_writes] || true @inner = CLibsql::Database.init desc return unless block_given? begin yield self ensure close end end |
Instance Method Details
#close ⇒ Object
581 582 583 584 585 586 |
# File 'lib/libsql.rb', line 581 def close raise ClosedException if closed? @inner.deinit @inner = nil end |
#closed? ⇒ Boolean
588 589 590 |
# File 'lib/libsql.rb', line 588 def closed? @inner.nil? end |
#connect ⇒ Object
571 572 573 574 575 576 577 578 579 |
# File 'lib/libsql.rb', line 571 def connect raise ClosedException if closed? conn = Connection.new @inner.connect return conn unless block_given? begin yield conn ensure conn.close end end |
#sync ⇒ Object
565 566 567 568 569 |
# File 'lib/libsql.rb', line 565 def sync raise ClosedException if closed? @inner.sync end |