allow result_set#each

This commit is contained in:
Brian J. Cardiff 2016-01-28 20:51:03 -03:00
parent 4dd0312934
commit c16dc42e96
2 changed files with 17 additions and 0 deletions

View file

@ -54,5 +54,16 @@ describe DummyDriver do
result_set.read(UInt64).should eq(1)
result_set.read(UInt64).should eq(2)
end
it "should enumerate records using each" do
nums = [] of UInt64
result_set = get_dummy.prepare("3,4 1,2").exec
result_set.each do
nums << result_set.read(UInt64)
nums << result_set.read(UInt64)
end
nums.should eq([3, 4, 1, 2])
end
end
end

View file

@ -5,6 +5,12 @@ module DB
def initialize(@statement : Statement)
end
def each
while has_next
yield
end
end
abstract def has_next : Bool
# def read(t : T.class) : T