Copyright | 2015 Dylan Simon |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Database.PostgreSQL.Typed.Enum
Description
Support for PostgreSQL enums.
Synopsis
- class (Eq a, Ord a, Enum a, Bounded a, PGRep a) => PGEnum a where
- pgEnumName :: a -> PGName
- pgEnumValue :: PGName -> Maybe a
- pgEnumValues :: [(a, PGName)]
- dataPGEnum :: String -> PGName -> (String -> String) -> DecsQ
Documentation
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
Methods
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.
Arguments
:: String | Haskell type to create |
-> PGName | PostgreSQL enum type name |
-> (String -> String) | How to generate constructor names from enum values, e.g. |
-> 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