SBDB::DB#[]=: If set to nil, it will delete item. SBDB::Cursor#each: Integer-keys for Recno and Queue.
This commit is contained in:
parent
8385dd2868
commit
ff2e444047
|
@ -12,12 +12,12 @@ module SBDB
|
|||
include Enumerable
|
||||
def bdb_object() @cursor end
|
||||
def close() @cursor.close end
|
||||
def get( k, v, f) @cursor.get k, v, f end
|
||||
def get( k, v, f) @cursor.get( k, v, f) end
|
||||
def count() @cursor.count end
|
||||
def first( k = nil, v = nil) @cursor.get k, v, FIRST end
|
||||
def last( k = nil, v = nil) @cursor.get k, v, LAST end
|
||||
def next( k = nil, v = nil) @cursor.get k, v, NEXT end
|
||||
def prev( k = nil, v = nil) @cursor.get k, v, PREV end
|
||||
def first( k = nil, v = nil) get k, v, FIRST end
|
||||
def last( k = nil, v = nil) get k, v, LAST end
|
||||
def next( k = nil, v = nil) get k, v, NEXT end
|
||||
def prev( k = nil, v = nil) get k, v, PREV end
|
||||
|
||||
def self.new *p
|
||||
x = super *p
|
||||
|
@ -33,6 +33,12 @@ module SBDB
|
|||
when Bdb::Db::Cursor then [ref]
|
||||
else [ref.bdb_object.cursor( nil, 0), ref]
|
||||
end
|
||||
if [Recno, Queue].any? {|t| t === @db }
|
||||
def get k, v, f
|
||||
l, w = @cursor.get( k, v, f)
|
||||
l.nil? ? nil : [l.unpack('I')[0], w]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reverse k = nil, v = nil, &e
|
||||
|
@ -42,10 +48,10 @@ module SBDB
|
|||
def each k = nil, v = nil, f = nil, n = nil
|
||||
return Enumerator.new( self, :each, k, v, f, n) unless block_given?
|
||||
n ||= NEXT
|
||||
e = @cursor.get k, v, f || FIRST
|
||||
e = get k, v, f || FIRST
|
||||
return unless e
|
||||
yield *e
|
||||
yield *e while e = @cursor.get( k, v, n)
|
||||
yield *e while e = get( k, v, n)
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@ module SBDB
|
|||
QUEUE = Bdb::Db::QUEUE
|
||||
ARRAY = RECNO = Bdb::Db::RECNO
|
||||
RDONLY = READLONY = Bdb::DB_RDONLY
|
||||
CONSUME = Bdb::DB_CONSUME
|
||||
CONSUME_WAIT = Bdb::DB_CONSUME_WAIT
|
||||
|
||||
attr_reader :home
|
||||
include Enumerable
|
||||
|
@ -16,9 +18,16 @@ module SBDB
|
|||
def sync() @db.sync end
|
||||
def close( f = nil) @db.close f || 0 end
|
||||
def []( k) @db.get nil, k.nil? ? nil : k.to_s, nil, 0 end
|
||||
def []=( k, v) @db.put nil, k.nil? ? nil : k.to_s, v.nil? ? nil : v.to_s, 0 end
|
||||
def cursor( &e) Cursor.new self, &e end
|
||||
|
||||
def []= k, v
|
||||
if v.nil?
|
||||
@db.del nil, k.to_s, 0
|
||||
else
|
||||
@db.put nil, k.nil? ? nil : k.to_s, v.to_s, 0
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def new *p, &e
|
||||
x = super *p
|
||||
|
@ -112,5 +121,9 @@ module SBDB
|
|||
def []= k, v
|
||||
super [k].pack('I'), v
|
||||
end
|
||||
|
||||
def unshift
|
||||
get nil, nil, nil, Bdb::DB_CONSUME
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue