@@ -64,6 +64,7 @@ module Squeal.PostgreSQL.PQ
6464 , resultErrorCode
6565 -- * Exceptions
6666 , SquealException (..)
67+ , PQState (..)
6768 , catchSqueal
6869 , handleSqueal
6970 ) where
@@ -613,14 +614,17 @@ resultErrorCode
613614 -> io (Maybe ByteString)
614615resultErrorCode = liftResult (flip LibPQ.resultErrorField LibPQ.DiagSqlstate)
615616
616−-- | `Exception`s that can be thrown by Squeal.
617−data SquealException
618− = PQException
617+-- | the state of LibPQ
618+data PQState = PQState
619619 { sqlExecStatus :: LibPQ.ExecStatus
620620 , sqlStateCode :: Maybe ByteString
621621 -- ^ https://www.postgresql.org/docs/current/static/errcodes-appendix.html
622622 , sqlErrorMessage :: Maybe ByteString
623− }
623+ } deriving (Eq, Show)
624+
625+-- | `Exception`s that can be thrown by Squeal.
626+data SquealException
627+ = PQException PQState
624628 | ResultException Text
625629 | ParseException Text
626630 deriving (Eq, Show)
@@ -638,7 +642,7 @@ tryResult result = liftIO $ do
638642 _ -> do
639643 stateCode <- LibPQ.resultErrorField result LibPQ.DiagSqlstate
640644 msg <- LibPQ.resultErrorMessage result
641− throw $ PQException status stateCode msg
645+ throw . PQException $ PQState status stateCode msg
642646
643647-- | Catch `SquealException`s.
644648catchSqueal