Add actual row number to row number errors
This commit is contained in:
parent
9e9e0204bb
commit
1c32e4244e
@ -59,11 +59,11 @@ instance RowContainer Maybe where
|
|||||||
extract result nRows columnTable
|
extract result nRows columnTable
|
||||||
| nRows == 0 = pure Nothing
|
| nRows == 0 = pure Nothing
|
||||||
| nRows == 1 = Just <$> ExceptT (fromRow result columnTable 0)
|
| nRows == 1 = Just <$> ExceptT (fromRow result columnTable 0)
|
||||||
| otherwise = throwE ErrorMoreThanOneRow
|
| otherwise = throwE $ ErrorMoreThanOneRow $ fromEnum nRows
|
||||||
|
|
||||||
instance RowContainer Identity where
|
instance RowContainer Identity where
|
||||||
extract result nRows columnTable = do
|
extract result nRows columnTable = do
|
||||||
unless (nRows == 1) $ throwE ErrorNotExactlyOneRow
|
unless (nRows == 1) $ throwE $ ErrorNotExactlyOneRow $ fromEnum nRows
|
||||||
Identity <$> ExceptT (fromRow result columnTable 0)
|
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.
|
-- 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.
|
||||||
|
@ -12,6 +12,7 @@ module Database.PostgreSQL.Opium.Connection
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Concurrent.MVar (MVar, newMVar, modifyMVar_, withMVar)
|
import Control.Concurrent.MVar (MVar, newMVar, modifyMVar_, withMVar)
|
||||||
|
import Control.Exception (Exception)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Database.PostgreSQL.LibPQ (ConnStatus (..))
|
import Database.PostgreSQL.LibPQ (ConnStatus (..))
|
||||||
@ -27,6 +28,8 @@ newtype Connection = Connection
|
|||||||
newtype ConnectionError = ConnectionError Text
|
newtype ConnectionError = ConnectionError Text
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
|
instance Exception ConnectionError
|
||||||
|
|
||||||
withRawConnection
|
withRawConnection
|
||||||
:: HasCallStack
|
:: HasCallStack
|
||||||
=> (Maybe LibPQ.Connection -> IO a)
|
=> (Maybe LibPQ.Connection -> IO a)
|
||||||
|
@ -17,8 +17,8 @@ data Error
|
|||||||
| ErrorInvalidOid Text Oid
|
| ErrorInvalidOid Text Oid
|
||||||
| ErrorUnexpectedNull ErrorPosition
|
| ErrorUnexpectedNull ErrorPosition
|
||||||
| ErrorInvalidField ErrorPosition Oid ByteString String
|
| ErrorInvalidField ErrorPosition Oid ByteString String
|
||||||
| ErrorNotExactlyOneRow
|
| ErrorNotExactlyOneRow Int
|
||||||
| ErrorMoreThanOneRow
|
| ErrorMoreThanOneRow Int
|
||||||
| ErrorConnectionClosed
|
| ErrorConnectionClosed
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user