groundhog-converters-0.1.0: Extended Converter Library for groundhog embedded types

CopyrightPlow Technologies LLC
LicenseMIT License
MaintainerScott Murphy
Safe HaskellNone
LanguageHaskell2010

Database.Groundhog.Converters

Description

This is a library for creating composable converters between datatypes for the purpose of inserting into a groundhog database.

The idea is to get from a representation a, which does not have a type class 'PersistEntity a' to one b, which has that type class defined.

This allows lightweight types libraries to coexist with nice database representations.

Synopsis

Documentation

makeConverter Source

Arguments

:: (a -> b)

Convert developer-facing type to database-storable type

-> (b -> a)

Convert database-storable type to developer-facing type

-> Converter a b 

Make a converter

There are preconditions on the input functions:

makeConverter f g
f (g x) = x
g (f x) = x

flipConverter :: Converter a b -> Converter b a Source

Reverse the direction of a converter

composeConverter :: Converter a b -> Converter b c -> Converter a c Source

Compose two converters

fmapConverter :: Functor f => Converter a b -> Converter (f a) (f b) Source

Map a converter over a functor

bicomposeConverter :: Converter a b -> Converter c d -> Converter (a, c) (b, d) Source

compose a First and Second Converter

firstConverter :: Converter a b -> Converter (a, c) (b, c) Source

Convert only the first element of a pair

secondConverter :: Converter a b -> Converter (c, a) (c, b) Source

Convert only the second element of a pair

jsonConverter :: (ToJSON a, FromJSON a) => Converter a ByteString Source

Convert via to and from JSON

integerConverter :: Converter Integer Int64 Source

Convert an Integer (which doesn't have a PersistField instance) to an Int64 (which does)

mapConverter :: Ord k => Converter (Map k v) [(k, v)] Source

Convert a Map to a list of key-value pairs

bimapConverter :: (Ord a, Ord b) => Converter (Bimap a b) [(a, b)] Source

Convert a Bimap to a list of key-value pairs

intMapConverter :: Converter (IntMap a) [(Int, a)] Source

Convert an IntMap to a list of Int-value pairs

type Converter a b = (a -> b, b -> a) Source

The type of a converter from a newtype or opaque type to a DB-serializable type