mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-22 18:22:05 +03:00
Enum
This commit is contained in:
parent
535b910fea
commit
9e684170a1
@ -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,
|
||||||
|
@ -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
|
||||||
-------------------------
|
-------------------------
|
||||||
|
@ -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
|
||||||
-------------------------
|
-------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user