mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Fixes query_one? handling no rows (#86)
This commit is contained in:
parent
be139c900c
commit
c54fab415e
2 changed files with 8 additions and 1 deletions
|
@ -190,6 +190,13 @@ describe DummyDriver do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "with as, no rows" do
|
||||||
|
with_dummy do |db|
|
||||||
|
value = db.query_one?("", as: {a: Int64, b: Int64})
|
||||||
|
value.should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "with as, just one" do
|
it "with as, just one" do
|
||||||
with_dummy do |db|
|
with_dummy do |db|
|
||||||
value = db.query_one?("3", as: Int64)
|
value = db.query_one?("3", as: Int64)
|
||||||
|
|
|
@ -169,7 +169,7 @@ module DB
|
||||||
# typeof(result) # => NamedTuple(age: String, name: Int32) | Nil
|
# typeof(result) # => NamedTuple(age: String, name: Int32) | Nil
|
||||||
# ```
|
# ```
|
||||||
def query_one?(query, *args, as types : NamedTuple)
|
def query_one?(query, *args, as types : NamedTuple)
|
||||||
query_one(query, *args) do |rs|
|
query_one?(query, *args) do |rs|
|
||||||
rs.read(**types)
|
rs.read(**types)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue