From 07e1c0924b240ddd1fd1f16892aff51cf047371e Mon Sep 17 00:00:00 2001 From: Tomasz Rybarczyk Date: Sun, 16 Dec 2018 20:02:24 +0100 Subject: [PATCH] More fine grained hoist function --- src/Database/PostgreSQL/PG.purs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Database/PostgreSQL/PG.purs b/src/Database/PostgreSQL/PG.purs index 44c9c63..d6ca6e6 100644 --- a/src/Database/PostgreSQL/PG.purs +++ b/src/Database/PostgreSQL/PG.purs @@ -5,7 +5,8 @@ module Database.PostgreSQL.PG , PG , command , execute -, hoistPG +, hoist +, hoistWith , query , onIntegrityError , scalar @@ -41,11 +42,14 @@ type Database = String -- | PGError a)`. type PG a = ExceptT PGError Aff a -hoistPG :: forall m. MonadAff m => PG ~> ExceptT PGError m -hoistPG m = ExceptT $ liftAff $ +hoistWith :: forall e m. MonadAff m => (PGError -> e) -> PG ~> ExceptT e m +hoistWith f m = ExceptT $ liftAff $ runExceptT m >>= case _ of Right a -> pure (Right a) - Left pgError -> pure (Left pgError) + Left pgError -> pure (Left (f pgError)) + +hoist :: forall m. MonadAff m => PG ~> ExceptT PGError m +hoist = hoistWith identity -- | Run an action with a connection. The connection is released to the pool -- | when the action returns.