class FDB::Database
Attributes
options[R]
Public Class Methods
finalize(ptr)
click to toggle source
# File lib/fdbimpl.rb, line 544 def self.finalize(ptr) proc do # puts "Destroying database #{ptr}" FDBC.fdb_database_destroy(ptr) end end
new(dpointer)
click to toggle source
# File lib/fdbimpl.rb, line 551 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
Public Instance Methods
clear(key)
click to toggle source
# File lib/fdbimpl.rb, line 605 def clear(key) transact do |tr| tr.clear(key) end end
clear_and_watch(key)
click to toggle source
# File lib/fdbimpl.rb, line 655 def clear_and_watch(key) transact do |tr| tr.clear(key) tr.watch(key) end end
clear_range(bkey, ekey)
click to toggle source
# File lib/fdbimpl.rb, line 611 def clear_range(bkey, ekey) transact do |tr| tr.clear_range(bkey, ekey) end end
clear_range_start_with(prefix)
click to toggle source
# File lib/fdbimpl.rb, line 634 def clear_range_start_with(prefix) transact do |tr| tr.clear_range_start_with(prefix) end end
create_transaction()
click to toggle source
# File lib/fdbimpl.rb, line 559 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)
click to toggle source
# File lib/fdbimpl.rb, line 587 def get(key) transact do |tr| tr[key].value end end
Also aliased as: []
get_and_watch(key)
click to toggle source
# File lib/fdbimpl.rb, line 640 def get_and_watch(key) transact do |tr| value = tr.get(key) watch = tr.watch(key) [value.value, watch] end end
get_key(keysel)
click to toggle source
# File lib/fdbimpl.rb, line 617 def get_key(keysel) transact do |tr| tr.get_key(keysel).value end end
get_range(bkeysel, ekeysel, options={}, &block)
click to toggle source
# File lib/fdbimpl.rb, line 594 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)
click to toggle source
# File lib/fdbimpl.rb, line 623 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)
click to toggle source
# File lib/fdbimpl.rb, line 580 def set(key, value) transact do |tr| tr[key] = value end end
Also aliased as: []=
set_and_watch(key, value)
click to toggle source
# File lib/fdbimpl.rb, line 648 def set_and_watch(key, value) transact do |tr| tr.set(key, value) tr.watch(key) end end
transact() { |tr| ... }
click to toggle source
# File lib/fdbimpl.rb, line 565 def transact tr = create_transaction committed = false begin ret = yield tr # puts ret tr.commit.wait committed = true rescue Error => e # puts "Rescued #{e}" tr.on_error(e).wait end until committed ret end
watch(key)
click to toggle source
# File lib/fdbimpl.rb, line 662 def watch(key) transact do |tr| tr.watch(key) end end