packages feed

hasql-2.2.0.0 / src / comms / Hasql / Comms / RowDecoder.hs

module Hasql.Comms.RowDecoder  ( RowDecoder,    nullableColumn,    nonNullableColumn,    -- * Relations    -- ** Expected OIDs    toExpectedOids,    -- ** Decoder    Decoder,    toDecoder,    -- * Errors    Error,  )whereimport Hasql.Comms.RowReader qualified as RowReaderimport Hasql.Platform.Preludeimport Pqi qualified as Pq-- * RowDecoderdata RowDecoder a  = RowDecoder      [Maybe Word32]      (RowReader.RowReader a)  deriving stock (Functor)instance Applicative RowDecoder where  pure a = RowDecoder [] (pure a)  RowDecoder lOids lDec <*> RowDecoder rOids rDec =    RowDecoder (lOids <> rOids) (lDec <*> rDec)instance Filterable RowDecoder where  mapMaybe fn (RowDecoder oids dec) =    RowDecoder oids (mapMaybe fn dec)-- * Functions-- |-- Next value, decoded using the provided value decoder.{-# INLINE nullableColumn #-}nullableColumn :: Maybe Word32 -> (ByteString -> Either Text a) -> RowDecoder (Maybe a)nullableColumn oid decoder =  RowDecoder    [oid]    (RowReader.nullableColumn decoder)-- |-- Next value, decoded using the provided value decoder.{-# INLINE nonNullableColumn #-}nonNullableColumn :: Maybe Word32 -> (ByteString -> Either Text a) -> RowDecoder anonNullableColumn oid decoder =  RowDecoder    [oid]    (RowReader.nonNullableColumn decoder)-- * Relations-- ** Expected OIDstoExpectedOids :: RowDecoder a -> [Maybe Word32]toExpectedOids (RowDecoder oids _) = oids-- ** Decodertype Decoder a = Pq.Result -> Int32 -> IO (Either Error a){-# INLINE toDecoder #-}toDecoder :: RowDecoder a -> Decoder atoDecoder (RowDecoder _ dec) result row =  RowReader.toHandler dec result row-- * Errorstype Error = RowReader.Error