Module: Persist::LMDBAdapter

Includes:
TSVAdapter
Defined in:
lib/rbbt/persist/tsv/lmdb.rb

Constant Summary

Constants included from TSVAdapter

TSVAdapter::MAX_CHAR

Instance Attribute Summary

Attributes included from TSVAdapter

#closed, #mutex, #persistence_path, #writable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TSVAdapter

#close, #closed?, #delete, #get_prefix, #merge!, #prefix, #range, #read?, #read_and_close, #write?, #write_and_close, #write_and_read

Class Method Details

.open(path, write) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rbbt/persist/tsv/lmdb.rb', line 7

def self.open(path, write)

  database = CONNECTIONS[path] ||= begin
                                     dir = File.dirname(File.expand_path(path))
                                     file = File.basename(path)
                                     env = LMDB.new(dir, :mapsize => 1024 * 10000)
                                     database = env.database file, :create => write
                                     database
                                   end

  database.extend Persist::LMDBAdapter unless Persist::LMDBAdapter === database
  database.persistence_path ||= path

  database
end

Instance Method Details

#collectObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rbbt/persist/tsv/lmdb.rb', line 32

def collect
  res = []
  cursor do |cursor|
    while pair = cursor.next
      res = if block_given?
              yield *pair
            else
              pair
            end
    end
  end
  res
end

#eachObject



23
24
25
26
27
28
29
30
# File 'lib/rbbt/persist/tsv/lmdb.rb', line 23

def each
  cursor do |cursor|
    while pair = cursor.next
      yield *pair
    end
  end
  self
end