postgresql-simple provides functions for streaming requests, for example
fold
:: (FromRow row, ToRow params)
=> Connection -> Query -> params -> a -> (a -> row -> IO a) -> IO a
I want to create a channel source that makes full use of streaming.
mySource :: (FromRow row, Monad m) => Source m row
Unfortunately, since it IOappears in a contravariant position (I think?) In fold, I really struggle with types. The following types are checked, but add up the entire stream to get the values.
getConduit :: Connection -> IO (C.ConduitM () Event IO ())
getConduit conn = fold_ conn queryEventRecord CL.sourceNull foo
where
foo :: C.ConduitM () Event IO () -> Event -> IO (C.ConduitM () Event IO ())
foo cond evt = pure (cond >> C.yield evt)
Any pointers on how to implement this would be greatly appreciated! Thank!
source
share