Navigation Menu

Skip to content

Commit

Permalink
mrb: add Database#each_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 26, 2016
1 parent 5c294e1 commit f81704d
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions lib/mrb/scripts/database.rb
@@ -1,41 +1,59 @@
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_raw(options=nil)
return to_enum(__method__, options) unless block_given?

def each_name(options={})
min = options[:prefix]
if options
min = options[:prefix]
order = options[:order]
order_by = options[:order_by]
else
min = nil
order = :ascending
order_by = :id
end
flags = 0
if options[:order] == :descending

if order == :descending
flags |= TableCursorFlags::DESCENDING
else
flags |= TableCursorFlags::ASCENDING
end
if options[:order_by] == :id
if 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|
name = cursor.key
yield(name)
yield(id, cursor)
end
end
end

def each(options=nil)
return to_enum(__method__, options) unless block_given?

context = Context.instance
each_raw(options) do |id, cursor|
object = context[id]
yield(object) if object
end
end

def each_name(options=nil)
return to_enum(__method__, options) unless block_given?

each_raw(options) do |id, cursor|
name = cursor.key
yield(name)
end
end

def each_table(options={})
return to_enum(__method__, options) unless block_given?

context = Context.instance
each_name(options) do |name|
next if name.include?(".")
Expand Down

0 comments on commit f81704d

Please sign in to comment.