postgresql-typed- PostgreSQL interface with compile-time SQL type checking, optional HDBC backend

Copyright2015 Dylan Simon
Safe HaskellNone



Support for PostgreSQL enums.



class (Eq a, Ord a, Enum a, Bounded a, PGRep a) => PGEnum a where Source #

A type based on a PostgreSQL enum. Automatically instantiated by dataPGEnum.

Minimal complete definition

pgEnumName | pgEnumValues


pgEnumName :: a -> PGName Source #

The database name of a value.

pgEnumValue :: PGName -> Maybe a Source #

Lookup a value matching the given database name.

pgEnumValues :: [(a, PGName)] Source #

List of all the values in the enum along with their database names.

dataPGEnum Source #


:: String

Haskell type to create

-> PGName

PostgreSQL enum type name

-> (String -> String)

How to generate constructor names from enum values, e.g. ("Type_"++) (input is pgNameString)

-> DecsQ 

Create a new enum type corresponding to the given PostgreSQL enum type. For example, if you have CREATE TYPE foo AS ENUM ('abc', 'DEF'), then dataPGEnum "Foo" "foo" ("Foo_"++) will be equivalent to:

data Foo = Foo_abc | Foo_DEF deriving (Eq, Ord, Enum, Bounded, Typeable)
instance PGType "foo" where PGVal "foo" = Foo
instance PGParameter "foo" Foo where ...
instance PGColumn "foo" Foo where ...
instance PGRep Foo where PGRepType = "foo"
instance PGEnum Foo where pgEnumValues = [(Foo_abc, "abc"), (Foo_DEF, "DEF")]

Requires language extensions: TemplateHaskell, FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable, DataKinds, TypeFamilies