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.
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/libsql.rb', line 525 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] unless [:sync_interval].nil? desc[:disable_read_your_writes] = ![:read_your_writes] unless [:read_your_writes].nil? @inner = CLibsql::Database.init desc return unless block_given? begin yield self ensure close end end |
Instance Method Details
#close ⇒ Object
558 559 560 561 562 563 |
# File 'lib/libsql.rb', line 558 def close raise ClosedException if closed? @inner.deinit @inner = nil end |
#closed? ⇒ Boolean
565 566 567 |
# File 'lib/libsql.rb', line 565 def closed? @inner.nil? end |
#connect ⇒ Object
548 549 550 551 552 553 554 555 556 |
# File 'lib/libsql.rb', line 548 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
542 543 544 545 546 |
# File 'lib/libsql.rb', line 542 def sync raise ClosedException if closed? @inner.sync end |