2016-06-28 17:02:08 +00:00
|
|
|
module DB
|
2020-09-14 13:49:00 +00:00
|
|
|
abstract class Connection
|
|
|
|
end
|
|
|
|
|
2016-06-28 17:02:08 +00:00
|
|
|
class Error < Exception
|
|
|
|
end
|
2016-03-28 23:45:07 +00:00
|
|
|
|
2017-11-08 02:18:43 +00:00
|
|
|
class MappingException < Error
|
2016-03-28 23:45:07 +00:00
|
|
|
end
|
2016-07-05 18:21:39 +00:00
|
|
|
|
|
|
|
class PoolTimeout < Error
|
|
|
|
end
|
2016-08-31 20:32:01 +00:00
|
|
|
|
|
|
|
class PoolRetryAttemptsExceeded < Error
|
|
|
|
end
|
|
|
|
|
2020-09-14 13:49:00 +00:00
|
|
|
class PoolResourceLost(T) < Error
|
|
|
|
getter resource : T
|
|
|
|
|
|
|
|
def initialize(@resource : T)
|
2021-09-10 11:36:01 +00:00
|
|
|
@resource.close
|
2020-09-14 13:49:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class PoolResourceRefused < Error
|
|
|
|
end
|
|
|
|
|
2016-12-15 17:40:56 +00:00
|
|
|
# Raised when an established connection is lost
|
|
|
|
# probably due to socket/network issues.
|
|
|
|
# It is used by the connection pool retry logic.
|
2020-09-14 13:49:00 +00:00
|
|
|
class ConnectionLost < PoolResourceLost(Connection)
|
|
|
|
def connection
|
|
|
|
resource
|
2016-08-31 20:32:01 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-16 02:46:11 +00:00
|
|
|
|
2016-12-15 17:40:56 +00:00
|
|
|
# Raised when a connection is unable to be established
|
|
|
|
# probably due to socket/network or configuration issues.
|
|
|
|
# It is used by the connection pool retry logic.
|
2020-09-14 13:49:00 +00:00
|
|
|
class ConnectionRefused < PoolResourceRefused
|
2016-12-15 17:40:56 +00:00
|
|
|
end
|
|
|
|
|
2017-11-08 02:18:43 +00:00
|
|
|
class Rollback < Error
|
2016-11-16 02:46:11 +00:00
|
|
|
end
|
2020-02-17 21:04:23 +00:00
|
|
|
|
|
|
|
# Raised when a scalar query returns no results.
|
|
|
|
class NoResultsError < Error
|
|
|
|
end
|
2021-10-12 23:49:26 +00:00
|
|
|
|
|
|
|
# Raised when the type returned for the column value
|
|
|
|
# does not match the type expected.
|
|
|
|
class ColumnTypeMismatchError < Error
|
|
|
|
getter column_index : Int32
|
|
|
|
getter column_name : String
|
|
|
|
getter column_type : String
|
|
|
|
getter expected_type : String
|
|
|
|
|
|
|
|
def initialize(*, context : String, @column_index : Int32, @column_name : String, @column_type : String, @expected_type : String)
|
|
|
|
super("In #{context} the column #{column_name} returned a #{column_type} but a #{expected_type} was expected.")
|
|
|
|
end
|
|
|
|
end
|
2016-06-28 17:02:08 +00:00
|
|
|
end
|