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.
514
515
516
517
518
519
520
|
# File 'lib/fdbimpl.rb', line 514
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.
505
506
507
|
# File 'lib/fdbimpl.rb', line 505
def options
@options
end
|
Class Method Details
.finalize(ptr) ⇒ Object
507
508
509
510
511
512
|
# File 'lib/fdbimpl.rb', line 507
def self.finalize(ptr)
proc do
FDBC.fdb_database_destroy(ptr)
end
end
|
Instance Method Details
#clear(key) ⇒ Object
568
569
570
571
572
|
# File 'lib/fdbimpl.rb', line 568
def clear(key)
transact do |tr|
tr.clear(key)
end
end
|
#clear_and_watch(key) ⇒ Object
618
619
620
621
622
623
|
# File 'lib/fdbimpl.rb', line 618
def clear_and_watch(key)
transact do |tr|
tr.clear(key)
tr.watch(key)
end
end
|
#clear_range(bkey, ekey) ⇒ Object
574
575
576
577
578
|
# File 'lib/fdbimpl.rb', line 574
def clear_range(bkey, ekey)
transact do |tr|
tr.clear_range(bkey, ekey)
end
end
|
#clear_range_start_with(prefix) ⇒ Object
597
598
599
600
601
|
# File 'lib/fdbimpl.rb', line 597
def clear_range_start_with(prefix)
transact do |tr|
tr.clear_range_start_with(prefix)
end
end
|
#create_transaction ⇒ Object
522
523
524
525
526
|
# File 'lib/fdbimpl.rb', line 522
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:
[]
550
551
552
553
554
|
# File 'lib/fdbimpl.rb', line 550
def get(key)
transact do |tr|
tr[key].value
end
end
|
#get_and_watch(key) ⇒ Object
603
604
605
606
607
608
609
|
# File 'lib/fdbimpl.rb', line 603
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
580
581
582
583
584
|
# File 'lib/fdbimpl.rb', line 580
def get_key(keysel)
transact do |tr|
tr.get_key(keysel).value
end
end
|
#get_range(bkeysel, ekeysel, options = {}, &block) ⇒ Object
557
558
559
560
561
562
563
564
565
566
|
# File 'lib/fdbimpl.rb', line 557
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
586
587
588
589
590
591
592
593
594
595
|
# File 'lib/fdbimpl.rb', line 586
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:
[]=
543
544
545
546
547
|
# File 'lib/fdbimpl.rb', line 543
def set(key, value)
transact do |tr|
tr[key] = value
end
end
|
#set_and_watch(key, value) ⇒ Object
611
612
613
614
615
616
|
# File 'lib/fdbimpl.rb', line 611
def set_and_watch(key, value)
transact do |tr|
tr.set(key, value)
tr.watch(key)
end
end
|
#transact ⇒ Object
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
# File 'lib/fdbimpl.rb', line 528
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
625
626
627
628
629
|
# File 'lib/fdbimpl.rb', line 625
def watch(key)
transact do |tr|
tr.watch(key)
end
end
|