Fixes query_one? handling no rows (#86)

This commit is contained in:
Rob David 2018-07-11 00:47:39 +01:00 committed by Brian J. Cardiff
parent be139c900c
commit c54fab415e
2 changed files with 8 additions and 1 deletions

View file

@ -190,6 +190,13 @@ describe DummyDriver do
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
with_dummy do |db|
value = db.query_one?("3", as: Int64)

View file

@ -169,7 +169,7 @@ module DB
# typeof(result) # => NamedTuple(age: String, name: Int32) | Nil
# ```
def query_one?(query, *args, as types : NamedTuple)
query_one(query, *args) do |rs|
query_one?(query, *args) do |rs|
rs.read(**types)
end
end