@@ -27,8 +27,6 @@ module Squeal.PostgreSQL.Pool
27 , createConnectionPool
27 , createConnectionPool
29 , destroyAllResources
29 , destroyAllResources
34import Control.Monad.Trans
32import Control.Monad.Trans
@@ -49,21 +47,23 @@ Typical use case would be to create your pool using `createConnectionPool` and r
50Here's a simplified example:
48Here's a simplified example:
52−> type Schema = '[ "tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint2])]
50+>>> import Squeal.PostgreSQL
54−> someQuery :: Manipulation Schema '[ 'NotNull 'PGint2] '[]
52+do
55−> someQuery = insertRow #tab
53+ let
56−> (Set (param @1) `As` #col :* Nil)
54+ query :: Query_ (Public '[]) () (Only Char)
57−> OnConflictDoNothing (Returning Nil)
55+ query = values_ $ literal 'a' `as` #fromOnly
58−>
56+ session :: PoolPQ (Public '[]) IO Char
59−> insertOne :: (MonadBaseControl IO m, MonadPQ Schema m) => m ()
57+ session = do
60−> insertOne = void $ manipulateParams someQuery . Only $ (1 :: Int16)
58+ result <- runQuery query
61−>
59+ Just (Only chr) <- firstRow result
62−> insertOneInPool :: ByteString -> IO ()
60+ return chr
63−> insertOneInPool connectionString = do
64−> pool <- createConnectionPool connectionString 1 0.5 10
61+ pool <- createConnectionPool "host=localhost port=5432 dbname=exampledb" 1 0.5 10
65−> liftIO $ runPoolPQ (insertOne) pool
62+ chr <- runPoolPQ session pool
66−
63+ destroyAllResources pool
68newtype PoolPQ (schemas :: SchemasType) m x =
68newtype PoolPQ (schemas :: SchemasType) m x =
69 PoolPQ { runPoolPQ :: Pool (K Connection schemas) -> m x }
69 PoolPQ { runPoolPQ :: Pool (K Connection schemas) -> m x }
@@ -152,12 +152,3 @@ instance (MonadUnliftIO m)
152 withRunInIO inner = PoolPQ $ \pool ->
152 withRunInIO inner = PoolPQ $ \pool ->
153 withRunInIO $ \(run :: (forall x . m x -> IO x)) ->
153 withRunInIO $ \(run :: (forall x . m x -> IO x)) ->
154 inner (\poolpq -> run $ runPoolPQ poolpq pool)
154 inner (\poolpq -> run $ runPoolPQ poolpq pool)
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
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)