postgresql-typed-0.4.0: A PostgreSQL access library with compile-time SQL type inference

Copyright2015 Dylan Simon
Safe HaskellNone
LanguageHaskell98

Database.PostgreSQL.Typed.Enum

Description

Support for PostgreSQL enums.

Synopsis

Documentation

class (Eq a, Ord a, Enum a, Bounded a, Show a) => PGEnum a Source

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

pgEnumValues :: PGEnum a => [(a, String)] Source

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

makePGEnum Source

Arguments

:: String

PostgreSQL enum type name

-> String

Haskell type to create

-> (String -> String)

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

-> 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 makePGEnum "foo" "Foo" ("Foo_"++) will be equivalent to:

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

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