Class: Libsql::Connection

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

Instance Method Summary collapse

Methods included from Prepareable

#execute, #query

Constructor Details

#initialize(inner) ⇒ Connection

Returns a new instance of Connection.



477
478
479
# File 'lib/libsql.rb', line 477

def initialize(inner)
  @inner = inner
end

Instance Method Details

#closeObject

Raises:



510
511
512
513
514
515
# File 'lib/libsql.rb', line 510

def close
  raise ClosedException if closed?

  @inner.deinit
  @inner = nil
end

#closed?Boolean

Returns:

  • (Boolean)


517
518
519
# File 'lib/libsql.rb', line 517

def closed?
  @inner.nil?
end

#execute_batch(sql) ⇒ Object



508
# File 'lib/libsql.rb', line 508

def execute_batch(sql) = @inner.execute_batch(sql)

#prepare(sql) ⇒ Object

Raises:



498
499
500
501
502
503
504
505
506
# File 'lib/libsql.rb', line 498

def prepare(sql)
  raise ClosedException if closed?

  stmt = Statement.new @inner.prepare sql

  return stmt unless block_given?

  begin yield stmt ensure stmt.close end
end

#transactionObject

Raises:



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/libsql.rb', line 481

def transaction
  raise ClosedException if closed?

  tx = Transaction.new @inner.transaction
  return tx unless block_given?

  abort = false
  begin
    yield self
  rescue StandardError
    abort = true
    raise
  ensure
    abort and tx.rollback or tx.commit
  end
end