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.



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/libsql.rb', line 548

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] || 0
  desc[:disable_read_your_writes] = !options[:read_your_writes] || true

  @inner = CLibsql::Database.init desc

  return unless block_given?

  begin yield self ensure close end
end

Instance Method Details

#closeObject

Raises:



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

Returns:

  • (Boolean)


588
589
590
# File 'lib/libsql.rb', line 588

def closed?
  @inner.nil?
end

#connectObject

Raises:



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

#syncObject

Raises:



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

def sync
  raise ClosedException if closed?

  @inner.sync
end