module Hasql.CursorQuery.Private.CursorTransactions whereimport qualified Control.Foldl as Dimport qualified Data.Text.Encoding as Textimport qualified Hasql.CursorQuery.Private.CursorQuery as Bimport qualified Hasql.CursorQuery.Private.Decoders as Iimport Hasql.CursorQuery.Private.Preludeimport qualified Hasql.CursorTransaction as Gimport qualified Hasql.Decoders as E-- |-- Fetch and fold the data from cursor until it dries out.fetchAndFoldCursor :: G.Cursor s -> G.BatchSize -> E.Row row -> D.Fold row result -> G.CursorTransaction s resultfetchAndFoldCursor cursor batchSize rowDecoder (D.Fold progress enter exit) = fmap exit $ fetchAndFoldMore enter where fetchAndFoldMore batch = do (null, fetchedBatch) <- fetchBatch if null then return batch else fetchAndFoldMore fetchedBatch where fetchBatch = fetchAndFoldCursorBatch cursor batchSize rowDecoder fold where fold = (,) <$> D.null <*> D.Fold progress batch idfetchAndFoldCursorBatch :: G.Cursor s -> G.BatchSize -> E.Row row -> D.Fold row result -> G.CursorTransaction s resultfetchAndFoldCursorBatch cursor batchSize rowDecoder rowsFold = G.fetchBatch cursor batchSize (I.fold rowsFold rowDecoder)-- |-- Executes CursorQuery in CursorTransaction provided the parameters.cursorQuery :: params -> B.CursorQuery params result -> G.CursorTransaction s resultcursorQuery params (B.CursorQuery template encoder (B.ReducingDecoder rowDecoder rowsFold) batchSize) = do cursor <- G.declareCursor (Text.decodeUtf8 template) (G.encodedParams encoder params) fetchAndFoldCursor cursor batchSize rowDecoder rowsFold