mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Allow query results to be read as named tuples directly (#56)
This commit is contained in:
parent
28b17b7dba
commit
d55a34e851
3 changed files with 82 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue