mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-22 10:05:27 +03:00
Enum
This commit is contained in:
parent
535b910fea
commit
9e684170a1
@ -68,7 +68,7 @@ library
|
||||
-- parsing:
|
||||
attoparsec >= 0.10 && < 0.14,
|
||||
-- database:
|
||||
postgresql-binary >= 0.7.2 && < 0.8,
|
||||
postgresql-binary >= 0.7.3 && < 0.8,
|
||||
postgresql-libpq == 0.9.*,
|
||||
-- data:
|
||||
dlist >= 0.7 && < 0.8,
|
||||
|
@ -45,6 +45,7 @@ module Hasql.Deserialization
|
||||
array,
|
||||
composite,
|
||||
hstore,
|
||||
enum,
|
||||
-- * Array
|
||||
Array,
|
||||
arrayDimension,
|
||||
@ -525,6 +526,13 @@ hstore :: (forall m. Monad m => Int -> m (Text, Maybe Text) -> m a) -> Value a
|
||||
hstore replicateM =
|
||||
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
|
||||
-------------------------
|
||||
|
@ -25,6 +25,7 @@ module Hasql.Serialization
|
||||
uuid,
|
||||
json,
|
||||
array,
|
||||
enum,
|
||||
-- * Array
|
||||
Array,
|
||||
arrayValue,
|
||||
@ -220,6 +221,15 @@ array (Array imp) =
|
||||
Array.run imp & \(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
|
||||
-------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user