@@ -27,8 +27,6 @@ module Squeal.PostgreSQL.Pool
2727 , createConnectionPool
2828 , Pool
2929 , destroyAllResources
30− , PoolPQRun
31− , poolpqliftWith
3230 ) where
3331
3432import Control.Monad.Trans
@@ -49,21 +47,23 @@ Typical use case would be to create your pool using `createConnectionPool` and r
4947
5048Here's a simplified example:
5149
52−> type Schema = '[ "tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint2])]
53−>
54−> someQuery :: Manipulation Schema '[ 'NotNull 'PGint2] '[]
55−> someQuery = insertRow #tab
56−> (Set (param @1) `As` #col :* Nil)
57−> OnConflictDoNothing (Returning Nil)
58−>
59−> insertOne :: (MonadBaseControl IO m, MonadPQ Schema m) => m ()
60−> insertOne = void $ manipulateParams someQuery . Only $ (1 :: Int16)
61−>
62−> insertOneInPool :: ByteString -> IO ()
63−> insertOneInPool connectionString = do
64−> pool <- createConnectionPool connectionString 1 0.5 10
65−> liftIO $ runPoolPQ (insertOne) pool
66−
50+>>> import Squeal.PostgreSQL
51+>>> :{
52+do
53+ let
54+ query :: Query_ (Public '[]) () (Only Char)
55+ query = values_ $ literal 'a' `as` #fromOnly
56+ session :: PoolPQ (Public '[]) IO Char
57+ session = do
58+ result <- runQuery query
59+ Just (Only chr) <- firstRow result
60+ return chr
61+ pool <- createConnectionPool "host=localhost port=5432 dbname=exampledb" 1 0.5 10
62+ chr <- runPoolPQ session pool
63+ destroyAllResources pool
64+ putChar chr
65+:}
66+a
6767-}
6868newtype PoolPQ (schemas :: SchemasType) m x =
6969 PoolPQ { runPoolPQ :: Pool (K Connection schemas) -> m x }
@@ -152,12 +152,3 @@ instance (MonadUnliftIO m)
152152 withRunInIO inner = PoolPQ $ \pool ->
153153 withRunInIO $ \(run :: (forall x . m x -> IO x)) ->
154154 inner (\poolpq -> run $ runPoolPQ poolpq pool)
155−
156−-- | A snapshot of the state of a `PoolPQ` computation.
157−type PoolPQRun schemas =
158− forall m x. Monad m => PoolPQ schemas m x -> m x
159−
160−-- | Helper function in defining `MonadBaseControl` instance for `PoolPQ`.
161−poolpqliftWith :: Functor m => (PoolPQRun schemas -> m a) -> PoolPQ schemas m a
162−poolpqliftWith f = PoolPQ $ \ pool ->
163− (f $ \ pq -> runPoolPQ pq pool)