rel8-internal
Safe HaskellNone
LanguageHaskell2010

Rel8.Internal.Type.Information

Synopsis

Documentation

data TypeInformation a Source #

TypeInformation describes how to encode and decode a Haskell type to and from database queries. The typeName is the name of the type in the database, which is used to accurately type literals.

Constructors

TypeInformation 

Fields

  • encode :: Encoder a

    How to serialize a Haskell value to PostgreSQL.

  • decode :: Decoder a

    How to deserialize a PostgreSQL result back to Haskell.

  • delimiter :: Char

    The delimiter that is used in PostgreSQL's text format in arrays of this type (this is almost always ',').

  • typeName :: TypeName

    The name of the SQL type.

mapTypeInformation :: (a -> b) -> (b -> a) -> TypeInformation a -> TypeInformation b Source #

Simultaneously map over how a type is both encoded and decoded, while retaining the name of the type. This operation is useful if you want to essentially newtype another DBType.

The mapping is required to be total. If you have a partial mapping, see parseTypeInformation.

parseTypeInformation :: (a -> Either String b) -> (b -> a) -> TypeInformation a -> TypeInformation b Source #

Apply a parser to TypeInformation.

This can be used if the data stored in the database should only be subset of a given TypeInformation. The parser is applied when deserializing rows returned - the encoder assumes that the input data is already in the appropriate form.