Add hoistPG function

This commit is contained in:
Tomasz Rybarczyk 2018-12-16 18:55:37 +01:00
parent a6deace1cb
commit 280320b553

View File

@ -27,6 +27,7 @@ import Database.PostgreSQL.Row (class FromSQLRow, class ToSQLRow, Row1)
import Database.PostgreSQL.Value (class FromSQLValue)
import Database.PostgreSQL.Value (class FromSQLValue, class ToSQLValue, fromSQLValue, instantFromString, instantToString, null, toSQLValue, unsafeIsBuffer) as Value
import Effect.Aff (Aff)
import Effect.Aff.Class (class MonadAff, liftAff)
type Database = String
@ -39,6 +40,12 @@ type Database = String
-- | PGError a)`.
type PG a = ExceptT PGError Aff a
hoistPG m. MonadAff m PG ~> ExceptT PGError m
hoistPG m = ExceptT $ liftAff $
runExceptT m >>= case _ of
Right a pure (Right a)
Left pgError pure (Left pgError)
-- | Run an action with a connection. The connection is released to the pool
-- | when the action returns.
withConnection
@ -118,3 +125,5 @@ onIntegrityError errorResult db =
case e of
IntegrityError _ -> errorResult
_ -> throwError e