Class: FDB::Database
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#block_until_ready, #on_ready, #ready?
Constructor Details
#initialize(dpointer) ⇒ Database
Returns a new instance of Database.
515
516
517
518
519
520
521
|
# File 'lib/fdbimpl.rb', line 515
def initialize(dpointer)
@dpointer = dpointer
@options = DatabaseOptions.new lambda { |code, param|
FDBC.check_error FDBC.fdb_database_set_option(dpointer, code, param, param.nil? ? 0 : param.bytesize)
}
ObjectSpace.define_finalizer(self, self.class.finalize(@dpointer))
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
506
507
508
|
# File 'lib/fdbimpl.rb', line 506
def options
@options
end
|
Class Method Details
.finalize(ptr) ⇒ Object
508
509
510
511
512
513
|
# File 'lib/fdbimpl.rb', line 508
def self.finalize(ptr)
proc do
FDBC.fdb_database_destroy(ptr)
end
end
|
Instance Method Details
#clear(key) ⇒ Object
569
570
571
572
573
|
# File 'lib/fdbimpl.rb', line 569
def clear(key)
transact do |tr|
tr.clear(key)
end
end
|
#clear_and_watch(key) ⇒ Object
619
620
621
622
623
624
|
# File 'lib/fdbimpl.rb', line 619
def clear_and_watch(key)
transact do |tr|
tr.clear(key)
tr.watch(key)
end
end
|
#clear_range(bkey, ekey) ⇒ Object
575
576
577
578
579
|
# File 'lib/fdbimpl.rb', line 575
def clear_range(bkey, ekey)
transact do |tr|
tr.clear_range(bkey, ekey)
end
end
|
#clear_range_start_with(prefix) ⇒ Object
598
599
600
601
602
|
# File 'lib/fdbimpl.rb', line 598
def clear_range_start_with(prefix)
transact do |tr|
tr.clear_range_start_with(prefix)
end
end
|
#create_transaction ⇒ Object
523
524
525
526
527
|
# File 'lib/fdbimpl.rb', line 523
def create_transaction
tr = FFI::MemoryPointer.new :pointer
FDBC.check_error FDBC.fdb_database_create_transaction(@dpointer, tr)
Transaction.new(tr.read_pointer, self)
end
|
#get(key) ⇒ Object
Also known as:
[]
551
552
553
554
555
|
# File 'lib/fdbimpl.rb', line 551
def get(key)
transact do |tr|
tr[key].value
end
end
|
#get_and_watch(key) ⇒ Object
604
605
606
607
608
609
610
|
# File 'lib/fdbimpl.rb', line 604
def get_and_watch(key)
transact do |tr|
value = tr.get(key)
watch = tr.watch(key)
[value.value, watch]
end
end
|
#get_key(keysel) ⇒ Object
581
582
583
584
585
|
# File 'lib/fdbimpl.rb', line 581
def get_key(keysel)
transact do |tr|
tr.get_key(keysel).value
end
end
|
#get_range(bkeysel, ekeysel, options = {}, &block) ⇒ Object
558
559
560
561
562
563
564
565
566
567
|
# File 'lib/fdbimpl.rb', line 558
def get_range(bkeysel, ekeysel, options={}, &block)
transact do |tr|
a = tr.get_range(bkeysel, ekeysel, options).to_a
if block_given?
a.each &block
else
a
end
end
end
|
#get_range_start_with(prefix, options = {}, &block) ⇒ Object
587
588
589
590
591
592
593
594
595
596
|
# File 'lib/fdbimpl.rb', line 587
def get_range_start_with(prefix, options={}, &block)
transact do |tr|
a = tr.get_range_start_with(prefix, options).to_a
if block_given?
a.each &block
else
a
end
end
end
|
#set(key, value) ⇒ Object
Also known as:
[]=
544
545
546
547
548
|
# File 'lib/fdbimpl.rb', line 544
def set(key, value)
transact do |tr|
tr[key] = value
end
end
|
#set_and_watch(key, value) ⇒ Object
612
613
614
615
616
617
|
# File 'lib/fdbimpl.rb', line 612
def set_and_watch(key, value)
transact do |tr|
tr.set(key, value)
tr.watch(key)
end
end
|
#transact ⇒ Object
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
# File 'lib/fdbimpl.rb', line 529
def transact
tr = create_transaction
committed = false
begin
ret = yield tr
tr.commit.wait
committed = true
rescue Error => e
tr.on_error(e).wait
end until committed
ret
end
|
#watch(key) ⇒ Object
626
627
628
629
630
|
# File 'lib/fdbimpl.rb', line 626
def watch(key)
transact do |tr|
tr.watch(key)
end
end
|