Add MonadFail instance for Row

This commit is contained in:
Renzo Carbonara 2020-05-09 18:12:42 +03:00
parent 46b836796e
commit 2c9c2377e1
2 changed files with 10 additions and 5 deletions

View File

@ -113,7 +113,7 @@ x = (,,) '<$>' ('column' . 'nullable') 'int8' '<*>' ('column' . 'nonNullable') '
@ @
-} -}
newtype Row a = Row (Row.Row a) newtype Row a = Row (Row.Row a)
deriving (Functor, Applicative, Monad) deriving (Functor, Applicative, Monad, MonadFail)
{-| {-|
Lift an individual non-nullable value decoder to a composable row decoder. Lift an individual non-nullable value decoder to a composable row decoder.

View File

@ -3,14 +3,19 @@ module Hasql.Private.Decoders.Row where
import Hasql.Private.Prelude hiding (error) import Hasql.Private.Prelude hiding (error)
import Hasql.Private.Errors import Hasql.Private.Errors
import qualified Database.PostgreSQL.LibPQ as LibPQ import qualified Database.PostgreSQL.LibPQ as LibPQ
import qualified Data.Text as T
import qualified PostgreSQL.Binary.Decoding as A import qualified PostgreSQL.Binary.Decoding as A
import qualified Hasql.Private.Decoders.Value as Value import qualified Hasql.Private.Decoders.Value as Value
import Control.Monad.Fail (MonadFail(..))
newtype Row a = newtype Row a =
Row (ReaderT Env (ExceptT RowError IO) a) Row (ReaderT Env (ExceptT RowError IO) a)
deriving (Functor, Applicative, Monad) deriving (Functor, Applicative, Monad)
instance MonadFail Row where
fail = error . ValueError . T.pack
data Env = data Env =
Env !LibPQ.Result !LibPQ.Row !LibPQ.Column !Bool !(IORef LibPQ.Column) Env !LibPQ.Result !LibPQ.Row !LibPQ.Column !Bool !(IORef LibPQ.Column)