generated from tpl/purs
feat: withPool
This commit is contained in:
parent
a0d2322441
commit
8160660a98
@ -110,6 +110,12 @@ transaction m =
|
|||||||
in
|
in
|
||||||
session $ begin *> catchError commit rollback
|
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
|
-- | Create a new connection pool from the provided config and execute
|
||||||
-- | the postgres monad, invoking `Effect.Aff.Postgres.Pool.end` afterwards.
|
-- | 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
|
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
|
acq = liftEffect $ Pool.make @r @missing @trash cfg
|
||||||
rel _ p = liftAff $ Pool.end p
|
rel _ p = liftAff $ Pool.end p
|
||||||
in
|
in
|
||||||
bracket acq rel $ runReaderT $ unwrap m
|
bracket acq rel $ withPool m
|
||||||
|
Loading…
Reference in New Issue
Block a user