Class: Libsql::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/libsql.rb

Instance Method Summary collapse

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(options = {})
  desc = CLibsql::DatabaseDesc.new

  %i[path url auth_token encryption_key].each do |sym|
    desc[sym] = FFI::MemoryPointer.from_string options[sym] unless options[sym].nil?
  end

  desc[:sync_interval] = options[:sync_interval] unless options[:sync_interval].nil?
  desc[:disable_read_your_writes] = !options[:read_your_writes] unless options[:read_your_writes].nil?

  @inner = CLibsql::Database.init desc

  return unless block_given?

  begin yield self ensure close end
end

Instance Method Details

#closeObject

Raises:



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

Returns:

  • (Boolean)


565
566
567
# File 'lib/libsql.rb', line 565

def closed?
  @inner.nil?
end

#connectObject

Raises:



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

#syncObject

Raises:



542
543
544
545
546
# File 'lib/libsql.rb', line 542

def sync
  raise ClosedException if closed?

  @inner.sync
end