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.
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/libsql.rb', line 523 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
556 557 558 559 560 561 |
# File 'lib/libsql.rb', line 556 def close raise ClosedException if closed? @inner.deinit @inner = nil end |
#closed? ⇒ Boolean
563 564 565 |
# File 'lib/libsql.rb', line 563 def closed? @inner.nil? end |
#connect ⇒ Object
546 547 548 549 550 551 552 553 554 |
# File 'lib/libsql.rb', line 546 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
540 541 542 543 544 |
# File 'lib/libsql.rb', line 540 def sync raise ClosedException if closed? @inner.sync end |