Add NoResultsError (#121)

This commit is contained in:
Jeremy Woertink 2020-02-17 13:04:23 -08:00 committed by GitHub
parent f128d6ddf3
commit f08a4da60a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -208,4 +208,13 @@ describe DB::Statement do
db.pool.is_available?(DummyDriver::DummyConnection.connections.first)
end
end
it "raises NoResultsError for scalar" do
with_dummy_connection do |cnn|
stmt = cnn.prepared ""
expect_raises DB::NoResultsError do
stmt.scalar "SELECT LIMIT 0"
end
end
end
end

View file

@ -29,4 +29,8 @@ module DB
class Rollback < Error
end
# Raised when a scalar query returns no results.
class NoResultsError < Error
end
end

View file

@ -15,7 +15,7 @@ module DB
end
end
raise "no results"
raise NoResultsError.new("no results")
end
# See `QueryMethods#query`