From 8160660a989bf65b9df1e74373ecc1006c4d5d43 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Wed, 3 Apr 2024 16:27:41 -0500 Subject: [PATCH] feat: withPool --- src/Control.Monad.Postgres.Base.purs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Control.Monad.Postgres.Base.purs b/src/Control.Monad.Postgres.Base.purs index f6f84dd..1808fc2 100644 --- a/src/Control.Monad.Postgres.Base.purs +++ b/src/Control.Monad.Postgres.Base.purs @@ -110,6 +110,12 @@ transaction m = in session $ begin *> catchError commit rollback +-- | Execute a `PostgresT` using an existing connection pool. +-- | +-- | This will not invoke `Pool.end` after executing. +withPool :: forall m a. PostgresT m a -> Pool -> m a +withPool = runReaderT <<< unwrap + -- | Create a new connection pool from the provided config and execute -- | the postgres monad, invoking `Effect.Aff.Postgres.Pool.end` afterwards. runPostgres :: forall m a missing trash r e f. MonadBracket e f m => MonadAff m => Union r missing (Pool.Config trash) => Record r -> PostgresT m a -> m a @@ -118,4 +124,4 @@ runPostgres cfg m = acq = liftEffect $ Pool.make @r @missing @trash cfg rel _ p = liftAff $ Pool.end p in - bracket acq rel $ runReaderT $ unwrap m + bracket acq rel $ withPool m