mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-26 12:01:35 +03:00
Add a Contravariant instance for Array encoder
This commit is contained in:
parent
d7d80ede8e
commit
3fcbcb23ba
@ -339,6 +339,7 @@ Please note that the PostgreSQL @IN@ keyword does not accept an array, but rathe
|
||||
values, thus this encoder is not suited for that. Use a @value = ANY($1)@ condition instead.
|
||||
-}
|
||||
newtype Array a = Array (Array.Array a)
|
||||
deriving (Contravariant)
|
||||
|
||||
{-|
|
||||
Lifts a 'Value' encoder into an 'Array' encoder.
|
||||
|
@ -9,6 +9,10 @@ import qualified Text.Builder as C
|
||||
data Array a =
|
||||
Array B.OID B.OID (Bool -> a -> A.Array) (a -> C.Builder)
|
||||
|
||||
instance Contravariant Array where
|
||||
contramap fn (Array valueOid arrayOid encoder renderer) =
|
||||
Array valueOid arrayOid (\ intDateTimes -> encoder intDateTimes . fn) (renderer . fn)
|
||||
|
||||
{-# INLINE value #-}
|
||||
value :: B.OID -> B.OID -> (Bool -> a -> A.Encoding) -> (a -> C.Builder) -> Array a
|
||||
value valueOID arrayOID encoder =
|
||||
|
Loading…
Reference in New Issue
Block a user