Allow query results to be read as named tuples directly (#56)

This commit is contained in:
Arthur Poulet 2017-12-29 23:32:25 +01:00 committed by Brian J. Cardiff
parent 28b17b7dba
commit d55a34e851
3 changed files with 82 additions and 0 deletions

View file

@ -138,6 +138,12 @@ describe DummyDriver do
end
end
it "with a named tuple" do
with_dummy do |db|
db.query_one("3,4", as: {a: Int64, b: Int64}).should eq({a: 3i64, b: 4i64})
end
end
it "with as, just one" do
with_dummy do |db|
db.query_one("3", as: Int64).should eq(3i64)
@ -176,6 +182,14 @@ describe DummyDriver do
end
end
it "with as" do
with_dummy do |db|
value = db.query_one?("3,4", as: {a: Int64, b: Int64})
value.should be_a(NamedTuple(a: Int64, b: Int64)?)
value.should eq({a: 3i64, b: 4i64})
end
end
it "with as, just one" do
with_dummy do |db|
value = db.query_one?("3", as: Int64)
@ -200,6 +214,13 @@ describe DummyDriver do
end
end
it "queries with a named tuple" do
with_dummy do |db|
ary = db.query_all "3,4 1,2", as: {a: Int64, b: Int64}
ary.should eq([{a: 3, b: 4}, {a: 1, b: 2}])
end
end
it "queries with as, just one" do
with_dummy do |db|
ary = db.query_all "3 1", as: Int64