summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/lib/mrb/scripts/database.rb
blob: 54d9dc1a6312868a4c8f4fb9ae1c80812a528a4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Groonga
  class Database
    def each
      context = Context.instance
      flags =
        TableCursorFlags::ASCENDING |
        TableCursorFlags::BY_ID
      TableCursor.open(self, :flags => flags) do |cursor|
        cursor.each do |id|
          object = context[id]
          yield(object) if object
        end
      end
    end

    def each_table(options={})
      context = Context.instance
      min = options[:prefix]
      flags = 0
      if options[:order] == :descending
        flags |= TableCursorFlags::DESCENDING
      else
        flags |= TableCursorFlags::ASCENDING
      end
      if options[:order_by] == :id
        flags |= TableCursorFlags::BY_ID
      else
        flags |= TableCursorFlags::BY_KEY
      end
      flags |= TableCursorFlags::PREFIX if min
      TableCursor.open(self, :min => min, :flags => flags) do |cursor|
        cursor.each do |id|
          object = context[id]
          yield(object) if object.is_a?(Table)
        end
      end
    end
  end
end