pipes-postgresql-simple 0.1.1.2 → 0.1.2.0
raw patch · 2 files changed
+28/−8 lines, 2 files
Files
pipes-postgresql-simple.cabal view
@@ -1,5 +1,5 @@ name: pipes-postgresql-simple-version: 0.1.1.2+version: 0.1.2.0 synopsis: Convert various postgresql-simple calls to work with pipes description: This library provides a few Producers and Consumers that allow @postgresql-simple@ calls to be made within the @pipes@ framework. Currently,
src/Pipes/PostgreSQL/Simple.hs view
@@ -3,6 +3,7 @@ module Pipes.PostgreSQL.Simple ( -- * Querying query,+ query_, -- * Serialization and Deserialization Format(..),@@ -41,14 +42,14 @@ query :: (MonadIO m, Pg.FromRow r, Pg.ToRow params) => Pg.Connection -> Pg.Query -> params -> Pipes.Producer r m ()-query c q p = do- (o, i, seal) <- liftIO (Pipes.spawn' Pipes.Single)- worker <- liftIO $ Async.async $ do- Pg.fold c q p () (const $ void . STM.atomically . Pipes.send o)- STM.atomically seal- liftIO $ Async.link worker- Pipes.fromInput i+query c q p = produceIO $ Pg.fold c q p () . const +-- | Like 'query', but it doesn't perform any query parameter substitution.+query_+ :: (MonadIO m, Pg.FromRow r)+ => Pg.Connection -> Pg.Query -> Pipes.Producer r m ()+query_ c q = produceIO $ Pg.fold_ c q () . const+ -------------------------------------------------------------------------------- -- | Convert a table to a byte stream. This is equivilent to a PostgreSQL -- @COPY ... TO@ statement.@@ -107,3 +108,22 @@ action `catchAll` \e -> handler e >> throwM e {-# INLINABLE toTable #-}++--------------------------------------------------------------------------------+-- Internal tools++-- | Build a 'Producer' from an 'IO' action by allowing said 'IO' action to+-- “yield” values in a streaming fashion.+produceIO+ :: MonadIO m+ => ((a -> IO ()) -> IO ()) -- ^ This action will be called once. It takes+ -- a function that “yields” an @a@ when called.+ -> Pipes.Producer a m ()+produceIO f = do+ (o, i, seal) <- liftIO $ Pipes.spawn' Pipes.Single+ worker <- liftIO $ Async.async $ do+ f $ \a -> void $ STM.atomically $ Pipes.send o a+ STM.atomically seal+ liftIO $ Async.link worker+ Pipes.fromInput i+