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.



490
491
492
# File 'lib/libsql.rb', line 490

def initialize(inner)
  @inner = inner
end

Instance Method Details

#closeObject

Raises:



535
536
537
538
539
540
# File 'lib/libsql.rb', line 535

def close
  raise ClosedException if closed?

  @inner.deinit
  @inner = nil
end

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @inner.nil?
end

#execute_batch(sql) ⇒ Object



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

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

#last_inserted_idObject

Raises:



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

def last_inserted_id
  raise ClosedException if closed?

  @inner.info[:last_inserted_id]
end

#prepare(sql) ⇒ Object

Raises:



523
524
525
526
527
528
529
530
531
# File 'lib/libsql.rb', line 523

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

#total_changesObject

Raises:



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

def total_changes
  raise ClosedException if closed?

  @inner.info[:total_changes]
end

#transactionObject

Raises:



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/libsql.rb', line 494

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