module Hasql.CursorQuery.Private.CursorQuery
where
import Hasql.CursorQuery.Private.Prelude
import qualified Hasql.Encoders as A
import qualified Hasql.Decoders as B
import qualified Control.Foldl as D
import qualified Hasql.CursorTransaction as H
data CursorQuery params result =
CursorQuery !ByteString !(A.Params params) !(ReducingDecoder result) !H.BatchSize
instance Profunctor CursorQuery where
dimap fn1 fn2 (CursorQuery template encoder decoder batchSize) =
CursorQuery template (contramap fn1 encoder) (fmap fn2 decoder) batchSize
instance Functor (CursorQuery params) where
fmap =
rmap
cursorQuery :: ByteString -> A.Params params -> ReducingDecoder result -> H.BatchSize -> CursorQuery params result
cursorQuery =
CursorQuery
data ReducingDecoder reduction =
forall row. ReducingDecoder !(B.Row row) !(D.Fold row reduction)
instance Functor ReducingDecoder where
fmap fn (ReducingDecoder rowDecoder rowsFold) =
ReducingDecoder rowDecoder (fmap fn rowsFold)
instance Applicative ReducingDecoder where
pure reduction =
ReducingDecoder (pure ()) (pure reduction)
(<*>) (ReducingDecoder rowDecoder1 rowsFold1) (ReducingDecoder rowDecoder2 rowsFold2) =
ReducingDecoder rowDecoder3 rowsFold3
where
rowDecoder3 =
strictPair <$> rowDecoder1 <*> rowDecoder2
where
strictPair !a !b =
(a, b)
rowsFold3 =
lmap fst rowsFold1 <*> lmap snd rowsFold2
reducingDecoder :: B.Row row -> D.Fold row reduction -> ReducingDecoder reduction
reducingDecoder =
ReducingDecoder