mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Enumerate columns in result_set
This commit is contained in:
parent
344804dd79
commit
5773faaa5c
2 changed files with 21 additions and 0 deletions
|
@ -41,5 +41,19 @@ describe DB::ResultSet do
|
|||
end
|
||||
the_rs.closed?.should be_true
|
||||
end
|
||||
|
||||
it "should enumerate columns" do
|
||||
cols = [] of String
|
||||
|
||||
with_dummy do |db|
|
||||
db.query "3,4 1,2" do |rs|
|
||||
rs.each_column do |col, col_type|
|
||||
cols << col
|
||||
col_type.should eq(Slice(UInt8))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
cols.should eq(["c0", "c1"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,6 +41,13 @@ module DB
|
|||
end
|
||||
end
|
||||
|
||||
# Iterates over all the columns
|
||||
def each_column
|
||||
column_count.times do |x|
|
||||
yield column_name(x), column_type(x)
|
||||
end
|
||||
end
|
||||
|
||||
# Move the next row in the result.
|
||||
# Return `false` if no more rows are available.
|
||||
# See `#each`
|
||||
|
|
Loading…
Reference in a new issue