mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-22 18:22:05 +03:00
Rearrange the encoders
This commit is contained in:
parent
799fbca0ed
commit
5fc68b7d92
@ -16,8 +16,6 @@ module Hasql.Encoders
|
||||
nullable,
|
||||
-- * Value
|
||||
Value,
|
||||
array,
|
||||
foldableArray,
|
||||
bool,
|
||||
int2,
|
||||
int4,
|
||||
@ -42,6 +40,8 @@ module Hasql.Encoders
|
||||
jsonbBytes,
|
||||
enum,
|
||||
unknown,
|
||||
array,
|
||||
foldableArray,
|
||||
-- * Array
|
||||
Array,
|
||||
element,
|
||||
|
@ -114,34 +114,6 @@ Value encoder.
|
||||
newtype Value a = Value (Value.Value a)
|
||||
deriving (Contravariant)
|
||||
|
||||
{-|
|
||||
Lift an array encoder into a parameter encoder.
|
||||
-}
|
||||
array :: Array a -> Value a
|
||||
array (Array (Array.Array valueOID arrayOID arrayEncoder renderer)) = let
|
||||
encoder env input = A.array (PTI.oidWord32 valueOID) (arrayEncoder env input)
|
||||
in Value (Value.Value arrayOID arrayOID encoder renderer)
|
||||
|
||||
{-|
|
||||
Lift a value encoder of element into a unidimensional array encoder of a foldable value.
|
||||
|
||||
E.g.,
|
||||
|
||||
@
|
||||
vectorOfInts :: Value (Vector Int64)
|
||||
vectorOfInts = 'foldableArray' ('nonNullable' 'int8')
|
||||
@
|
||||
|
||||
This function is merely a shortcut for the following expression:
|
||||
|
||||
@
|
||||
('array' . 'dimension' 'foldl'' . 'element')
|
||||
@
|
||||
-}
|
||||
{-# INLINE foldableArray #-}
|
||||
foldableArray :: Foldable foldable => NullableOrNot Value a -> Value (foldable a)
|
||||
foldableArray = array . dimension foldl' . element
|
||||
|
||||
{-|
|
||||
Encoder of @BOOL@ values.
|
||||
-}
|
||||
@ -320,6 +292,34 @@ section of the Postgres' documentation.
|
||||
unknown :: Value ByteString
|
||||
unknown = Value (Value.unsafePTIWithShow PTI.unknown (const A.bytea_strict))
|
||||
|
||||
{-|
|
||||
Lift an array encoder into a parameter encoder.
|
||||
-}
|
||||
array :: Array a -> Value a
|
||||
array (Array (Array.Array valueOID arrayOID arrayEncoder renderer)) = let
|
||||
encoder env input = A.array (PTI.oidWord32 valueOID) (arrayEncoder env input)
|
||||
in Value (Value.Value arrayOID arrayOID encoder renderer)
|
||||
|
||||
{-|
|
||||
Lift a value encoder of element into a unidimensional array encoder of a foldable value.
|
||||
|
||||
E.g.,
|
||||
|
||||
@
|
||||
vectorOfInts :: Value (Vector Int64)
|
||||
vectorOfInts = 'foldableArray' ('nonNullable' 'int8')
|
||||
@
|
||||
|
||||
This function is merely a shortcut for the following expression:
|
||||
|
||||
@
|
||||
('array' . 'dimension' 'foldl'' . 'element')
|
||||
@
|
||||
-}
|
||||
{-# INLINE foldableArray #-}
|
||||
foldableArray :: Foldable foldable => NullableOrNot Value a -> Value (foldable a)
|
||||
foldableArray = array . dimension foldl' . element
|
||||
|
||||
|
||||
-- * Array
|
||||
-------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user