Copyright | (c) 2011 MailRank Inc. |
---|---|
License | BSD3 |
Maintainer | Paul Rouse <[email protected]> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Database.MySQL.Simple.Result
Description
The Result
typeclass, for converting a single value in a row
returned by a SQL query into a more useful Haskell representation.
A Haskell numeric type is considered to be compatible with all
MySQL numeric types that are less accurate than it. For instance,
the Haskell Double
type is compatible with the MySQL Long
type
because it can represent a Long
exactly. On the other hand, since
a Double
might lose precision if representing a LongLong
, the
two are not considered compatible.
Synopsis
- class FromField a where
- fromField :: ([Type], ByteString -> Either String a)
- class Result a where
- convert :: Field -> Maybe ByteString -> a
- data ResultError
- = Incompatible { }
- | UnexpectedNull { }
- | ConversionFailed { }
Documentation
class FromField a where Source #
A type that can be converted from a ByteString
. Any type which is
an instance of this class, and is Typeable
, can use the default
implementation of Result
. This provides a method of implementing
a decoder for any text-like column, such as TEXT
, BLOB
, or JSON
,
instead of implementing Result
directly.
The first component of the tuple returned by fromField
is a list of
acceptable column types, expressed in terms of
Type
.
Since: 0.4.8
A type that may be converted from a SQL type.
A default implementation is provided for any type which is an instance
of both FromField
and Typeable
, providing a simple mechanism for
user-defined decoding from text- or blob-like fields (including JSON
).
Minimal complete definition
Nothing
Methods
convert :: Field -> Maybe ByteString -> a Source #
Convert a SQL value to a Haskell value.
Throws a ResultError
if conversion fails.
Instances
data ResultError Source #
Exception thrown if conversion from a SQL value to a Haskell value fails.
Constructors
Incompatible | The SQL and Haskell types are not compatible. |
Fields
| |
UnexpectedNull | A SQL |
Fields
| |
ConversionFailed | The SQL value could not be parsed, or could not be represented as a valid Haskell value, or an unexpected low-level error occurred (e.g. mismatch between metadata and actual data in a row). |
Fields
|
Instances
Exception ResultError Source # | |
Defined in Database.MySQL.Simple.Result Methods toException :: ResultError -> SomeException # fromException :: SomeException -> Maybe ResultError # displayException :: ResultError -> String # | |
Show ResultError Source # | |
Defined in Database.MySQL.Simple.Result Methods showsPrec :: Int -> ResultError -> ShowS # show :: ResultError -> String # showList :: [ResultError] -> ShowS # | |
Eq ResultError Source # | |
Defined in Database.MySQL.Simple.Result |