More fine grained hoist function

This commit is contained in:
Tomasz Rybarczyk 2018-12-16 20:02:24 +01:00
parent a04090da0b
commit 07e1c0924b

View File

@ -5,7 +5,8 @@ module Database.PostgreSQL.PG
, PG , PG
, command , command
, execute , execute
, hoistPG , hoist
, hoistWith
, query , query
, onIntegrityError , onIntegrityError
, scalar , scalar
@ -41,11 +42,14 @@ type Database = String
-- | PGError a)`. -- | PGError a)`.
type PG a = ExceptT PGError Aff a type PG a = ExceptT PGError Aff a
hoistPG :: forall m. MonadAff m => PG ~> ExceptT PGError m hoistWith :: forall e m. MonadAff m => (PGError -> e) -> PG ~> ExceptT e m
hoistPG m = ExceptT $ liftAff $ hoistWith f m = ExceptT $ liftAff $
runExceptT m >>= case _ of runExceptT m >>= case _ of
Right a -> pure (Right a) 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 -- | Run an action with a connection. The connection is released to the pool
-- | when the action returns. -- | when the action returns.