Copyright | (c) Moritz Kiefer 2017 |
---|---|
License | BSD-3 |
Maintainer | moritz.kiefer@purelyfunctional.org |
Safe Haskell | None |
Language | Haskell2010 |
This module provides the machinery for implementing instances of
FromRow
that deserialize based on the names of columns instead of
the positions of individual fields. This is particularly convenient
when deserializing to a Haskell record and you want the field names
and column names to match up. In this case gFromRow
can be used as
a generic implementation of fromRow
.
- gFromRow :: forall a modName tyName constrName fields xs. (Generic a, HasDatatypeInfo a, All2 FromField (Code a), KnownSymbol modName, KnownSymbol tyName, DatatypeInfoOf a ~ ADT modName tyName '[Record constrName fields], Code a ~ '[xs], DemoteFieldInfos fields xs) => RowParser a
- fieldByName :: FromField a => ByteString -> RowParser a
- fieldByNameWith :: FieldParser a -> ByteString -> RowParser a
- data NoSuchColumn = NoSuchColumn ByteString
- data TooManyColumns = TooManyColumns {
- numRecordFields :: !Word
- numColumns :: !Word
Generic implementation of FromRow
gFromRow :: forall a modName tyName constrName fields xs. (Generic a, HasDatatypeInfo a, All2 FromField (Code a), KnownSymbol modName, KnownSymbol tyName, DatatypeInfoOf a ~ ADT modName tyName '[Record constrName fields], Code a ~ '[xs], DemoteFieldInfos fields xs) => RowParser a Source #
Deserialize a type with a single record constructor by matching the names of columns and record fields. Currently the complexity is O(n^2) where n is the number of record fields.
This is intended to be used as the implementation of fromRow
.
Throws
NoSuchColumn
if there is a field for which there is no column with the same name.TooManyColumns
if there more columns (counting both named and unnamed columns) than record fields.
Deserialize individual fields based on their name
:: FromField a | |
=> ByteString | column name to look for |
-> RowParser a |
This is a wrapper around fieldByNameWith
that gets the
FieldParser
via the typeclass instance. Take a look at the docs
for fieldByNameWith
for the details of this function.
:: FieldParser a | |
-> ByteString | column name to look for |
-> RowParser a |
This is similar to fieldWith
but instead of trying to
deserialize the field at the current position it goes through all
fields in the current row (starting at the beginning not the
current position) and tries to deserialize the first field with a
matching column name.
Exception types
data NoSuchColumn Source #
Thrown when there is no column of the given name.
data TooManyColumns Source #
Thrown by gFromRow
when trying to deserialize to a record that
has less fields than the current row has columns (counting both
named and unnamed columns).
TooManyColumns | |
|