postgresql-named-0.1.0: Generic deserialization of PostgreSQL rows based on column names

Copyright(c) Moritz Kiefer 2017
LicenseBSD-3
Maintainermoritz.kiefer@purelyfunctional.org
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Simple.FromRow.Named

Contents

Description

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.

Synopsis

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

fieldByName Source #

Arguments

:: 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.

fieldByNameWith Source #

Arguments

:: 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 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).

Constructors

TooManyColumns 

Fields