mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Raise a specific class error instead of string literal (#156)
* Raise a specific class error instead of string literal when the type returned doesn't match the type expected. Allows for drivers to catch the specific error. * Add ResultSet#next_column_index * Add shared specs for next_column_index * Add properties to ColumnTypeMismatchError * Add shared specs for ColumnTypeMismatchError * Fix specs Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>
This commit is contained in:
parent
a25f33611c
commit
b1299fcada
5 changed files with 92 additions and 3 deletions
|
@ -20,6 +20,10 @@ module GenericResultSet
|
|||
@index += 1
|
||||
@row[@index - 1]
|
||||
end
|
||||
|
||||
def next_column_index : Int32
|
||||
@index
|
||||
end
|
||||
end
|
||||
|
||||
class FooValue
|
||||
|
@ -197,7 +201,7 @@ describe DB do
|
|||
FooDriver.fake_row = [1] of FooDriver::Any
|
||||
db.query "query" do |rs|
|
||||
rs.move_next
|
||||
expect_raises(Exception, "FooResultSet#read returned a Int32. A BarValue was expected.") do
|
||||
expect_raises(DB::ColumnTypeMismatchError, "In FooDriver::FooResultSet#read the column 0 returned a Int32 but a BarValue was expected.") do
|
||||
w.check
|
||||
rs.read(BarValue)
|
||||
end
|
||||
|
@ -210,7 +214,7 @@ describe DB do
|
|||
BarDriver.fake_row = [1] of BarDriver::Any
|
||||
db.query "query" do |rs|
|
||||
rs.move_next
|
||||
expect_raises(Exception, "BarResultSet#read returned a Int32. A FooValue was expected.") do
|
||||
expect_raises(DB::ColumnTypeMismatchError, "In BarDriver::BarResultSet#read the column 0 returned a Int32 but a FooValue was expected.") do
|
||||
w.check
|
||||
rs.read(FooValue)
|
||||
end
|
||||
|
|
|
@ -190,6 +190,10 @@ class DummyDriver < DB::Driver
|
|||
return n
|
||||
end
|
||||
|
||||
def next_column_index : Int32
|
||||
@column_count - @values.not_nil!.size
|
||||
end
|
||||
|
||||
def read(t : String.class)
|
||||
read.to_s
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue