module Hasql.Private.Decoders.Array where

import Hasql.Private.Prelude
import qualified PostgreSQL.Binary.Decoding as A

newtype Array a
  = Array (ReaderT Bool A.Array a)
  deriving (forall a b. a -> Array b -> Array a
forall a b. (a -> b) -> Array a -> Array b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Array b -> Array a
$c<$ :: forall a b. a -> Array b -> Array a
fmap :: forall a b. (a -> b) -> Array a -> Array b
$cfmap :: forall a b. (a -> b) -> Array a -> Array b
Functor)

{-# INLINE run #-}
run :: Array a -> Bool -> A.Value a
run :: forall a. Array a -> Bool -> Value a
run (Array ReaderT Bool Array a
imp) Bool
env =
  forall a. Array a -> Value a
A.array (forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Bool Array a
imp Bool
env)

{-# INLINE dimension #-}
dimension :: (forall m. Monad m => Int -> m a -> m b) -> Array a -> Array b
dimension :: forall a b.
(forall (m :: * -> *). Monad m => Int -> m a -> m b)
-> Array a -> Array b
dimension forall (m :: * -> *). Monad m => Int -> m a -> m b
replicateM (Array ReaderT Bool Array a
imp) =
  forall a. ReaderT Bool Array a -> Array a
Array forall a b. (a -> b) -> a -> b
$ forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ \Bool
env -> forall a b.
(forall (m :: * -> *). Monad m => Int -> m a -> m b)
-> Array a -> Array b
A.dimensionArray forall (m :: * -> *). Monad m => Int -> m a -> m b
replicateM (forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Bool Array a
imp Bool
env)

{-# INLINE value #-}
value :: (Bool -> A.Value a) -> Array (Maybe a)
value :: forall a. (Bool -> Value a) -> Array (Maybe a)
value Bool -> Value a
decoder' =
  forall a. ReaderT Bool Array a -> Array a
Array forall a b. (a -> b) -> a -> b
$ forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ forall a. Value a -> Array (Maybe a)
A.nullableValueArray forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Value a
decoder'

{-# INLINE nonNullValue #-}
nonNullValue :: (Bool -> A.Value a) -> Array a
nonNullValue :: forall a. (Bool -> Value a) -> Array a
nonNullValue Bool -> Value a
decoder' =
  forall a. ReaderT Bool Array a -> Array a
Array forall a b. (a -> b) -> a -> b
$ forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ forall a. Value a -> Array a
A.valueArray forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Value a
decoder'