fixes for database
This commit is contained in:
parent
ea38686c2c
commit
110221e983
|
@ -26,7 +26,7 @@ class Bdb::Database
|
|||
primary_db = environment.env.db
|
||||
primary_db.pagesize = config[:page_size] if config[:page_size]
|
||||
primary_db.open(transaction, name, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
||||
@db[:primary] = primary_db
|
||||
@db[:primary_key] = primary_db
|
||||
|
||||
indexes.each do |field, opts|
|
||||
index_callback = lambda do |db, key, data|
|
||||
|
@ -49,7 +49,7 @@ class Bdb::Database
|
|||
end
|
||||
end
|
||||
end
|
||||
@db[index || :primary]
|
||||
@db[index || :primary_key]
|
||||
end
|
||||
|
||||
def close
|
||||
|
@ -75,20 +75,15 @@ class Bdb::Database
|
|||
flags = 0 if environment.disable_transactions?
|
||||
|
||||
keys.each do |key|
|
||||
if opts[:partial] and not key.kind_of?(Range) and not key == :all
|
||||
first = [*key]
|
||||
last = first + [true]
|
||||
key = first..last
|
||||
end
|
||||
|
||||
key = get_key(key, opts)
|
||||
if key == :all
|
||||
with_cursor(db) do |cursor|
|
||||
if opts[:reverse]
|
||||
k,v = cursor.get(nil, nil, Bdb::DB_LAST | flags) # Start at the last item.
|
||||
iter = lambda {cursor.get(nil, nil, Bdb::DB_PREV | flags)} # Move backward.
|
||||
k,v = cursor.get(nil, nil, Bdb::DB_LAST | flags) # Start at the last item.
|
||||
iter = lambda {cursor.get(nil, nil, Bdb::DB_PREV | flags)} # Move backward.
|
||||
else
|
||||
k,v = cursor.get(nil, nil, Bdb::DB_FIRST | flags) # Start at the first item.
|
||||
iter = lambda {cursor.get(nil, nil, Bdb::DB_NEXT | flags)} # Move forward.
|
||||
k,v = cursor.get(nil, nil, Bdb::DB_FIRST | flags) # Start at the first item.
|
||||
iter = lambda {cursor.get(nil, nil, Bdb::DB_NEXT | flags)} # Move forward.
|
||||
end
|
||||
|
||||
while k
|
||||
|
@ -189,6 +184,15 @@ class Bdb::Database
|
|||
|
||||
private
|
||||
|
||||
def get_key(key, opts)
|
||||
if opts[:partial] and not key.kind_of?(Range) and not key == :all
|
||||
first = [*key]
|
||||
last = first + [true]
|
||||
key = first..last
|
||||
end
|
||||
key
|
||||
end
|
||||
|
||||
def unmarshal(value, opts = {})
|
||||
value = Marshal.load(value)
|
||||
value.bdb_locator_key = opts[:tuple] ? Tuple.load(opts[:tuple]) : [*opts[:key]]
|
||||
|
@ -227,13 +231,13 @@ private
|
|||
attr_reader :count, :group, :limit, :offset, :results
|
||||
|
||||
def <<(item)
|
||||
key = item[1]
|
||||
@count += 1
|
||||
return if count <= offset
|
||||
|
||||
raise LimitReached if limit and count > limit + offset
|
||||
|
||||
if group
|
||||
key = item.bdb_locator_key
|
||||
group_key = group.is_a?(Fixnum) ? key[0,group] : key
|
||||
(results[group_key] ||= []) << item
|
||||
elsif @block
|
||||
|
|
Loading…
Reference in a new issue