Add actual row number to row number errors

This commit is contained in:
Paul Brinkmeier 2025-08-20 22:22:21 +02:00
parent 9e9e0204bb
commit 1c32e4244e
3 changed files with 7 additions and 4 deletions

View File

@ -59,11 +59,11 @@ instance RowContainer Maybe where
extract result nRows columnTable
| nRows == 0 = pure Nothing
| nRows == 1 = Just <$> ExceptT (fromRow result columnTable 0)
| otherwise = throwE ErrorMoreThanOneRow
| otherwise = throwE $ ErrorMoreThanOneRow $ fromEnum nRows
instance RowContainer Identity where
extract result nRows columnTable = do
unless (nRows == 1) $ throwE ErrorNotExactlyOneRow
unless (nRows == 1) $ throwE $ ErrorNotExactlyOneRow $ fromEnum nRows
Identity <$> ExceptT (fromRow result columnTable 0)
-- The order of the type parameters is important, because it is more common to use type applications for providing the row type and row container type.

View File

@ -12,6 +12,7 @@ module Database.PostgreSQL.Opium.Connection
) where
import Control.Concurrent.MVar (MVar, newMVar, modifyMVar_, withMVar)
import Control.Exception (Exception)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Database.PostgreSQL.LibPQ (ConnStatus (..))
@ -27,6 +28,8 @@ newtype Connection = Connection
newtype ConnectionError = ConnectionError Text
deriving (Show)
instance Exception ConnectionError
withRawConnection
:: HasCallStack
=> (Maybe LibPQ.Connection -> IO a)

View File

@ -17,8 +17,8 @@ data Error
| ErrorInvalidOid Text Oid
| ErrorUnexpectedNull ErrorPosition
| ErrorInvalidField ErrorPosition Oid ByteString String
| ErrorNotExactlyOneRow
| ErrorMoreThanOneRow
| ErrorNotExactlyOneRow Int
| ErrorMoreThanOneRow Int
| ErrorConnectionClosed
deriving (Eq, Show)