2024-01-27 00:23:09 +03:00
|
|
|
module Hasql.Decoders.Array where
|
2015-11-08 21:09:42 +03:00
|
|
|
|
2024-01-27 00:23:09 +03:00
|
|
|
import Hasql.Prelude
|
2024-04-19 07:38:30 +03:00
|
|
|
import PostgreSQL.Binary.Decoding qualified as A
|
2015-11-08 21:09:42 +03:00
|
|
|
|
2022-06-20 13:54:54 +03:00
|
|
|
newtype Array a
|
|
|
|
= Array (ReaderT Bool A.Array a)
|
2015-11-08 21:09:42 +03:00
|
|
|
deriving (Functor)
|
|
|
|
|
|
|
|
{-# INLINE run #-}
|
2017-03-20 23:13:21 +03:00
|
|
|
run :: Array a -> Bool -> A.Value a
|
2015-11-08 21:09:42 +03:00
|
|
|
run (Array imp) env =
|
2017-03-20 23:13:21 +03:00
|
|
|
A.array (runReaderT imp env)
|
2015-11-08 21:09:42 +03:00
|
|
|
|
|
|
|
{-# INLINE dimension #-}
|
2023-10-13 02:24:12 +03:00
|
|
|
dimension :: (forall m. (Monad m) => Int -> m a -> m b) -> Array a -> Array b
|
2015-11-08 21:09:42 +03:00
|
|
|
dimension replicateM (Array imp) =
|
2017-03-20 23:13:21 +03:00
|
|
|
Array $ ReaderT $ \env -> A.dimensionArray replicateM (runReaderT imp env)
|
2015-11-08 21:09:42 +03:00
|
|
|
|
|
|
|
{-# INLINE value #-}
|
2017-03-20 23:13:21 +03:00
|
|
|
value :: (Bool -> A.Value a) -> Array (Maybe a)
|
2015-11-08 21:09:42 +03:00
|
|
|
value decoder' =
|
2017-03-20 23:13:21 +03:00
|
|
|
Array $ ReaderT $ A.nullableValueArray . decoder'
|
2015-11-08 21:09:42 +03:00
|
|
|
|
|
|
|
{-# INLINE nonNullValue #-}
|
2017-03-20 23:13:21 +03:00
|
|
|
nonNullValue :: (Bool -> A.Value a) -> Array a
|
2015-11-08 21:09:42 +03:00
|
|
|
nonNullValue decoder' =
|
2017-03-20 23:13:21 +03:00
|
|
|
Array $ ReaderT $ A.valueArray . decoder'
|