module Hasql.Streaming (
streamingQuery,
) where
import Streaming
import Streaming.Prelude as Streaming
import Hasql.Statement
import Hasql.CursorTransactionIO
import Hasql.Streams
streamingQuery ::
Statement params [a] -> params ->
Stream (Of a) (CursorTransactionIO s) ()
streamingQuery :: Statement params [a]
-> params -> Stream (Of a) (CursorTransactionIO s) ()
streamingQuery Statement params [a]
stmt params
params = Statement params [a]
-> params
-> CursorStreamFold s a (Stream (Of a) (CursorTransactionIO s) ())
-> Stream (Of a) (CursorTransactionIO s) ()
forall params s a r.
Statement params [a] -> params -> CursorStreamFold s a r -> r
cursorStreamQuery Statement params [a]
stmt params
params CursorStreamFold s a (Stream (Of a) (CursorTransactionIO s) ())
forall s a.
CursorStreamFold s a (Stream (Of a) (CursorTransactionIO s) ())
foldStreamingStream
foldStreamingStream ::
CursorStreamFold s a (Stream (Of a) (CursorTransactionIO s) ())
foldStreamingStream :: (x -> CursorTransactionIO s (Maybe (a, x)))
-> CursorTransactionIO s x
-> Stream (Of a) (CursorTransactionIO s) ()
foldStreamingStream x -> CursorTransactionIO s (Maybe (a, x))
step CursorTransactionIO s x
init = CursorTransactionIO s x -> Stream (Of a) (CursorTransactionIO s) x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift CursorTransactionIO s x
init Stream (Of a) (CursorTransactionIO s) x
-> (x -> Stream (Of a) (CursorTransactionIO s) ())
-> Stream (Of a) (CursorTransactionIO s) ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (x -> CursorTransactionIO s (Either () (a, x)))
-> x -> Stream (Of a) (CursorTransactionIO s) ()
forall (m :: * -> *) s r a.
Monad m =>
(s -> m (Either r (a, s))) -> s -> Stream (Of a) m r
Streaming.unfoldr ((Maybe (a, x) -> Either () (a, x))
-> CursorTransactionIO s (Maybe (a, x))
-> CursorTransactionIO s (Either () (a, x))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe (a, x) -> Either () (a, x)
forall a. Maybe a -> Either () a
maybeToEither (CursorTransactionIO s (Maybe (a, x))
-> CursorTransactionIO s (Either () (a, x)))
-> (x -> CursorTransactionIO s (Maybe (a, x)))
-> x
-> CursorTransactionIO s (Either () (a, x))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> CursorTransactionIO s (Maybe (a, x))
step)
maybeToEither :: Maybe a -> Either () a
maybeToEither :: Maybe a -> Either () a
maybeToEither = Either () a -> (a -> Either () a) -> Maybe a -> Either () a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> Either () a
forall a b. a -> Either a b
Left ()) a -> Either () a
forall a b. b -> Either a b
Right