Stability | experimental |
---|---|
Maintainer | Leon P Smith <leon@melding-monads.com> |
Safe Haskell | None |
The FromRow
typeclass, for converting a row of results
returned by a SQL query into a more useful Haskell representation.
Predefined instances are provided for tuples containing up to ten
elements. The instances for Maybe
types return Nothing
if all
the columns that would have been otherwise consumed are null, otherwise
it attempts a regular conversion.
Documentation
A collection type that can be converted from a sequence of fields. Instances are provided for tuples up to 10 elements and lists of any length.
Note that instances can be defined outside of postgresql-simple, which is often useful. For example, here's an instance for a user-defined pair:
data User = User { name :: String, fileQuota :: Int } instanceFromRow
User where fromRow = User <$>field
<*>field
The number of calls to field
must match the number of fields returned
in a single row of the query result. Otherwise, a ConversionFailed
exception will be thrown.
Note that field
evaluates it's result to WHNF, so the caveats listed in
mysql-simple and very early versions of postgresql-simple no longer apply.
Instead, look at the caveats associated with user-defined implementations
of fromField
.
fieldWith :: FieldParser a -> RowParser aSource