This commit is contained in:
Nikita Volkov 2015-11-10 17:53:14 +03:00
parent 535b910fea
commit 9e684170a1
3 changed files with 19 additions and 1 deletions

View File

@ -68,7 +68,7 @@ library
-- parsing: -- parsing:
attoparsec >= 0.10 && < 0.14, attoparsec >= 0.10 && < 0.14,
-- database: -- database:
postgresql-binary >= 0.7.2 && < 0.8, postgresql-binary >= 0.7.3 && < 0.8,
postgresql-libpq == 0.9.*, postgresql-libpq == 0.9.*,
-- data: -- data:
dlist >= 0.7 && < 0.8, dlist >= 0.7 && < 0.8,

View File

@ -45,6 +45,7 @@ module Hasql.Deserialization
array, array,
composite, composite,
hstore, hstore,
enum,
-- * Array -- * Array
Array, Array,
arrayDimension, arrayDimension,
@ -525,6 +526,13 @@ hstore :: (forall m. Monad m => Int -> m (Text, Maybe Text) -> m a) -> Value a
hstore replicateM = hstore replicateM =
Value (Value.decoder (const (Decoder.hstore replicateM Decoder.text_strict Decoder.text_strict))) Value (Value.decoder (const (Decoder.hstore replicateM Decoder.text_strict Decoder.text_strict)))
-- |
-- Given a partial mapping from text to value,
-- produces a deserializer of that value.
enum :: (Text -> Maybe a) -> Value a
enum mapping =
Value (Value.decoder (const (Decoder.enum mapping)))
-- ** Instances -- ** Instances
------------------------- -------------------------

View File

@ -25,6 +25,7 @@ module Hasql.Serialization
uuid, uuid,
json, json,
array, array,
enum,
-- * Array -- * Array
Array, Array,
arrayValue, arrayValue,
@ -220,6 +221,15 @@ array (Array imp) =
Array.run imp & \(arrayOID, encoder') -> Array.run imp & \(arrayOID, encoder') ->
Value (Value.Value arrayOID arrayOID encoder') Value (Value.Value arrayOID arrayOID encoder')
-- |
-- Given a function,
-- which maps the value into the textual enum label from the DB side,
-- produces a serializer of that value.
{-# INLINABLE enum #-}
enum :: (a -> Text) -> Value a
enum mapping =
Value (Value.unsafePTI PTI.text (const (Encoder.enum mapping)))
-- ** Instances -- ** Instances
------------------------- -------------------------