{-# LANGUAGE ExistentialQuantification, GADTs, InstanceSigs, MagicHash #-}
module Hmssql.Decoding
(
FromSqlField (fieldDecoder, fieldRowDecoder)
, FieldDecoder (..)
, fieldDecoderFor
, fieldDecoderForTypes
, refineField
, nullableField
, RawValue (..)
, dayTimeFieldDecoder
, dateTimeOffsetFieldDecoder
, timeFieldDecoder
, decimalFieldDecoder
, ValueStream (..), streamField, streamTextField
, FromSqlRow (..)
, RowDecoder (..)
, singleField
, inlinedField
, inlinedNullableField
, byColumn
, genericFromSqlRow
, RowDecoderMonadic (..)
, singleFieldM
, remainingColumns
, toMonadicRowDecoder
, sqlRowDecoder
, sqlValueDecoder
, sqlRowDecoderFor
, compileField
, CellDecoder (..)
, StreamedValue (..)
, streamWholeLimit
, ReadFailure (..)
, decodeCell
, fieldDecoderCompiled
, readCellRecipe
, compileRowDecoder
, compileRowDecoderFor
, compileMonadicRowDecoder
, skipRowDecoder
, CompiledRow (..)
, Prepared (..)
, rowRecipe
, decodeColumnChunks
, decodeColumnText
) where
import Control.Monad (when)
import Streaming (Stream, Of)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB
import Data.Coerce (Coercible, coerce)
import Data.Decimal (Decimal, DecimalRaw (..))
import Data.Int (Int16, Int32, Int64, Int8)
import GHC.Exts (Int64#)
import GHC.Int (Int64 (I64#))
import Data.Primitive.SmallArray (indexSmallArray)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import Data.Time
import Data.Tuple.Only (Only (..))
import Data.UUID.Types (UUID)
import Data.Word (Word64, Word8)
import GHC.Generics
import Hmssql.Errors (DecodeError (..))
import Hmssql.SqlValue
import Hmssql.Internal.SqlDataType (SqlDataType (..))
import Hmssql.Tds.Scalar
import Hmssql.Tds.CodePage (decodeCodecChunks)
import Hmssql.Tds.Context
import Hmssql.Tds.Primitives
import Hmssql.Tds.Value
import Hmssql.Tds.Token (ColumnInfo (..), ResultSetInfo, compileResultSet, rsColumnArray, rsColumnCount, rsColumns, rsCells)
import Hmssql.Tds.TypeInfo
import qualified Hmssql.Tds.Utf16 as Utf16
import Hmssql.Tds.Parser (Parser)
import qualified Hmssql.Tds.Parser as P
import Hmssql.Tds.Reader (CompiledRow (..), Prepared (..), ReadFailure (..), rowRecipe)
newtype FieldDecoder a = FieldDecoder
(TdsContext -> ColumnInfo -> Either String (CellDecoder a))
data CellDecoder a
= CellDecoder (Either String a) (ValueReader a) (ValueReader a)
| FoldingCell (Either String a) (ValueReader a) (ValueReader a)
(Stream (Of B.ByteString) Parser () -> Parser (Either ReadFailure a))
| StreamingCell (StreamedValue -> Parser (Either ReadFailure a))
data StreamedValue
= StreamedNull
| StreamedWhole !P.ValueBytes
| StreamedBytes !(Maybe Int64) (Stream (Of B.ByteString) Parser ())
streamWholeLimit :: Int
streamWholeLimit :: Int
streamWholeLimit = Int
64 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024
instance Functor CellDecoder where
fmap :: forall a b. (a -> b) -> CellDecoder a -> CellDecoder b
fmap a -> b
f (CellDecoder Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned) =
Either [Char] b -> ValueReader b -> ValueReader b -> CellDecoder b
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder ((a -> b) -> Either [Char] a -> Either [Char] b
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Either [Char] a
onNull) ((a -> b) -> Either [Char] a -> Either [Char] b
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Either [Char] a -> Either [Char] b)
-> ValueReader a -> ValueReader b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
borrowed) ((a -> b) -> Either [Char] a -> Either [Char] b
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Either [Char] a -> Either [Char] b)
-> ValueReader a -> ValueReader b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
owned)
fmap a -> b
f (FoldingCell Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold) =
Either [Char] b
-> ValueReader b
-> ValueReader b
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure b))
-> CellDecoder b
forall a.
Either [Char] a
-> ValueReader a
-> ValueReader a
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> CellDecoder a
FoldingCell ((a -> b) -> Either [Char] a -> Either [Char] b
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Either [Char] a
onNull) ((a -> b) -> Either [Char] a -> Either [Char] b
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Either [Char] a -> Either [Char] b)
-> ValueReader a -> ValueReader b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
borrowed) ((a -> b) -> Either [Char] a -> Either [Char] b
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Either [Char] a -> Either [Char] b)
-> ValueReader a -> ValueReader b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
owned) ((Either ReadFailure a -> Either ReadFailure b)
-> Parser (Either ReadFailure a) -> Parser (Either ReadFailure b)
forall a b. (a -> b) -> Recipe () a -> Recipe () b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> Either ReadFailure a -> Either ReadFailure b
forall a b.
(a -> b) -> Either ReadFailure a -> Either ReadFailure b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (Parser (Either ReadFailure a) -> Parser (Either ReadFailure b))
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold)
fmap a -> b
f (StreamingCell StreamedValue -> Parser (Either ReadFailure a)
d) = (StreamedValue -> Parser (Either ReadFailure b)) -> CellDecoder b
forall a.
(StreamedValue -> Parser (Either ReadFailure a)) -> CellDecoder a
StreamingCell ((Either ReadFailure a -> Either ReadFailure b)
-> Parser (Either ReadFailure a) -> Parser (Either ReadFailure b)
forall a b. (a -> b) -> Recipe () a -> Recipe () b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> Either ReadFailure a -> Either ReadFailure b
forall a b.
(a -> b) -> Either ReadFailure a -> Either ReadFailure b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (Parser (Either ReadFailure a) -> Parser (Either ReadFailure b))
-> (StreamedValue -> Parser (Either ReadFailure a))
-> StreamedValue
-> Parser (Either ReadFailure b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StreamedValue -> Parser (Either ReadFailure a)
d)
instance Functor FieldDecoder where
fmap :: forall a b. (a -> b) -> FieldDecoder a -> FieldDecoder b
fmap = (a -> b) -> FieldDecoder a -> FieldDecoder b
forall a b. (a -> b) -> FieldDecoder a -> FieldDecoder b
mapField
{-# INLINE fmap #-}
mapField :: (a -> b) -> FieldDecoder a -> FieldDecoder b
mapField :: forall a b. (a -> b) -> FieldDecoder a -> FieldDecoder b
mapField a -> b
f (FieldDecoder TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile) = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder b))
-> FieldDecoder b
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder b))
-> FieldDecoder b)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder b))
-> FieldDecoder b
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> (CellDecoder a -> CellDecoder b)
-> Either [Char] (CellDecoder a) -> Either [Char] (CellDecoder b)
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> CellDecoder a -> CellDecoder b
forall a b. (a -> b) -> CellDecoder a -> CellDecoder b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile TdsContext
ctx ColumnInfo
col)
{-# OPAQUE mapField #-}
compileField :: FieldDecoder a -> TdsContext -> ColumnInfo -> Either String (CellDecoder a)
compileField :: forall a.
FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compileField (FieldDecoder TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile) = TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile
{-# INLINE compileField #-}
fieldDecoderCompiled :: (TdsContext -> ColumnInfo -> Either String (CellDecoder a)) -> FieldDecoder a
fieldDecoderCompiled :: forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
fieldDecoderCompiled = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder
{-# INLINE fieldDecoderCompiled #-}
decodeCell :: CellDecoder a -> RawBytes -> Either String a
decodeCell :: forall a. CellDecoder a -> RawBytes -> Either [Char] a
decodeCell (CellDecoder Either [Char] a
onNull ValueReader a
_ ValueReader a
owned) = Either [Char] a -> ValueReader a -> RawBytes -> Either [Char] a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either [Char] a
onNull ValueReader a
owned
decodeCell (FoldingCell Either [Char] a
onNull ValueReader a
_ ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
_) = Either [Char] a -> ValueReader a -> RawBytes -> Either [Char] a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either [Char] a
onNull ValueReader a
owned
decodeCell (StreamingCell StreamedValue -> Parser (Either ReadFailure a)
_) = Either [Char] a -> RawBytes -> Either [Char] a
forall a b. a -> b -> a
const ([Char] -> Either [Char] a
forall a b. a -> Either a b
Left [Char]
"a streaming field requires a live value stream")
cellDecoder :: Either String a -> ValueReader a -> CellDecoder a
cellDecoder :: forall a. Either [Char] a -> ValueReader a -> CellDecoder a
cellDecoder Either [Char] a
onNull ValueReader a
decode = Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder Either [Char] a
onNull ValueReader a
converted ValueReader a
converted
where converted :: ValueReader a
converted ByteString
bytes = ValueReader a
decode ByteString
bytes Either [Char] a -> (a -> Either [Char] a) -> Either [Char] a
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] a
forall a. a -> Either [Char] a
evaluated
{-# INLINE cellDecoder #-}
instance Semigroup (FieldDecoder a) where
FieldDecoder TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
f <> :: FieldDecoder a -> FieldDecoder a -> FieldDecoder a
<> FieldDecoder TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
g = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> case TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
f TdsContext
ctx ColumnInfo
col of
Right CellDecoder a
d -> CellDecoder a -> Either [Char] (CellDecoder a)
forall a b. b -> Either a b
Right CellDecoder a
d
Left [Char]
e1 -> case TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
g TdsContext
ctx ColumnInfo
col of
Right CellDecoder a
d -> CellDecoder a -> Either [Char] (CellDecoder a)
forall a b. b -> Either a b
Right CellDecoder a
d
Left [Char]
e2 -> [Char] -> Either [Char] (CellDecoder a)
forall a b. a -> Either a b
Left ([Char]
e1 [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"; " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
e2)
{-# INLINE (<>) #-}
class FromSqlField a where
fieldDecoder :: FieldDecoder a
fieldRowDecoder :: RowDecoder a
fieldRowDecoder = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder (\TdsContext
ctx ResultSetInfo
rs Int
i -> RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
compileRowAt (Nulls a a -> RowDecoder a
forall a b. FromSqlField a => Nulls a b -> RowDecoder b
forall b. Nulls a b -> RowDecoder b
rowDecoderWith Nulls a a
forall a. Nulls a a
NoNulls) TdsContext
ctx ResultSetInfo
rs Int
i) Int
1
nullableRowDecoder :: RowDecoder (Maybe a)
nullableRowDecoder = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart (Maybe a)))
-> Int -> RowDecoder (Maybe a)
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder (\TdsContext
ctx ResultSetInfo
rs Int
i -> RowDecoder (Maybe a)
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart (Maybe a))
forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
compileRowAt (Nulls a (Maybe a) -> RowDecoder (Maybe a)
forall a b. FromSqlField a => Nulls a b -> RowDecoder b
forall b. Nulls a b -> RowDecoder b
rowDecoderWith Nulls a (Maybe a)
forall a. Nulls a (Maybe a)
Nulls) TdsContext
ctx ResultSetInfo
rs Int
i) Int
1
rowDecoderWith :: Nulls a b -> RowDecoder b
rowDecoderWith Nulls a b
nulls = FieldDecoder b -> RowDecoder b
forall a. FieldDecoder a -> RowDecoder a
singleField (Nulls a b -> FieldDecoder a -> FieldDecoder b
forall a b. Nulls a b -> FieldDecoder a -> FieldDecoder b
nullsField Nulls a b
nulls FieldDecoder a
forall a. FromSqlField a => FieldDecoder a
fieldDecoder)
fieldDecoderFor :: String -> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> B.ByteString -> Either String a) -> FieldDecoder a
fieldDecoderFor :: forall a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> ByteString -> Either [Char] a)
-> FieldDecoder a
fieldDecoderFor [Char]
name TypeInfo -> Bool
accepts TdsContext -> TypeInfo -> ByteString -> Either [Char] a
decode = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] (TdsContext, TypeInfo))
-> ((TdsContext, TypeInfo) -> ByteString -> Either [Char] a)
-> FieldDecoder a
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name TypeInfo -> Bool
accepts
(\TdsContext
ctx TypeInfo
ti -> (TdsContext, TypeInfo) -> Either [Char] (TdsContext, TypeInfo)
forall a b. b -> Either a b
Right (TdsContext
ctx, TypeInfo
ti)) (\(TdsContext
ctx, TypeInfo
ti) ByteString
bs -> TdsContext -> TypeInfo -> ByteString -> Either [Char] a
decode TdsContext
ctx TypeInfo
ti ByteString
bs)
{-# INLINE fieldDecoderFor #-}
fieldDecoderForTypes :: String -> (SqlDataType -> Bool)
-> (TdsContext -> TypeInfo -> B.ByteString -> Either String a) -> FieldDecoder a
fieldDecoderForTypes :: forall a.
[Char]
-> (SqlDataType -> Bool)
-> (TdsContext -> TypeInfo -> ByteString -> Either [Char] a)
-> FieldDecoder a
fieldDecoderForTypes [Char]
name SqlDataType -> Bool
accepts = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> ByteString -> Either [Char] a)
-> FieldDecoder a
forall a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> ByteString -> Either [Char] a)
-> FieldDecoder a
fieldDecoderFor [Char]
name ((SqlDataType -> Bool) -> TypeInfo -> Bool
hasDataType SqlDataType -> Bool
accepts)
compiledFieldDecoder :: String -> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either String s) -> (s -> ValueReader a) -> FieldDecoder a
compiledFieldDecoder :: forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name TypeInfo -> Bool
accepts TdsContext -> TypeInfo -> Either [Char] s
select s -> ValueReader a
reader = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col ->
let ti :: TypeInfo
ti = ColumnInfo -> TypeInfo
columnType ColumnInfo
col
in if TypeInfo -> Bool
accepts TypeInfo
ti
then do
selected <- TdsContext -> TypeInfo -> Either [Char] s
select TdsContext
ctx TypeInfo
ti
pure (cellDecoder (nullAs name) (reader selected))
else [Char] -> Either [Char] (CellDecoder a)
forall a b. a -> Either a b
Left ([Char] -> TypeInfo -> [Char]
rejectAs [Char]
name TypeInfo
ti)
{-# INLINE compiledFieldDecoder #-}
nullAs :: String -> Either String a
nullAs :: forall a. [Char] -> Either [Char] a
nullAs [Char]
name = [Char] -> Either [Char] a
forall a b. a -> Either a b
Left ([Char] -> Either [Char] a) -> [Char] -> Either [Char] a
forall a b. (a -> b) -> a -> b
$ [Char]
"SQL NULL cannot be decoded as " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
name [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"; use Maybe " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
name
evaluated :: a -> Either String a
evaluated :: forall a. a -> Either [Char] a
evaluated a
a = a
a a -> Either [Char] a -> Either [Char] a
forall a b. a -> b -> b
`seq` a -> Either [Char] a
forall a b. b -> Either a b
Right a
a
bytesDecoder :: String -> (TypeInfo -> Bool) -> (B.ByteString -> a) -> FieldDecoder a
bytesDecoder :: forall a.
[Char] -> (TypeInfo -> Bool) -> (ByteString -> a) -> FieldDecoder a
bytesDecoder [Char]
name TypeInfo -> Bool
accepts ByteString -> a
mk = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a b. (a -> b) -> a -> b
$ \TdsContext
_ ColumnInfo
col ->
let ti :: TypeInfo
ti = ColumnInfo -> TypeInfo
columnType ColumnInfo
col
in if TypeInfo -> Bool
accepts TypeInfo
ti
then CellDecoder a -> Either [Char] (CellDecoder a)
forall a b. b -> Either a b
Right (CellDecoder a -> Either [Char] (CellDecoder a))
-> CellDecoder a -> Either [Char] (CellDecoder a)
forall a b. (a -> b) -> a -> b
$ Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder ([Char] -> Either [Char] a
forall a. [Char] -> Either [Char] a
nullAs [Char]
name)
(\ByteString
bytes -> a -> Either [Char] a
forall a b. b -> Either a b
Right (a -> Either [Char] a) -> a -> Either [Char] a
forall a b. (a -> b) -> a -> b
$! ByteString -> a
mk (ByteString -> ByteString
B.copy ByteString
bytes)) (\ByteString
bytes -> a -> Either [Char] a
forall a b. b -> Either a b
Right (a -> Either [Char] a) -> a -> Either [Char] a
forall a b. (a -> b) -> a -> b
$! ByteString -> a
mk ByteString
bytes)
else [Char] -> Either [Char] (CellDecoder a)
forall a b. a -> Either a b
Left ([Char] -> TypeInfo -> [Char]
rejectAs [Char]
name TypeInfo
ti)
{-# INLINE bytesDecoder #-}
nullableField :: FieldDecoder a -> FieldDecoder (Maybe a)
nullableField :: forall a. FieldDecoder a -> FieldDecoder (Maybe a)
nullableField (FieldDecoder TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile) = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder (Maybe a)))
-> FieldDecoder (Maybe a)
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext
-> ColumnInfo -> Either [Char] (CellDecoder (Maybe a)))
-> FieldDecoder (Maybe a))
-> (TdsContext
-> ColumnInfo -> Either [Char] (CellDecoder (Maybe a)))
-> FieldDecoder (Maybe a)
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> (CellDecoder a -> CellDecoder (Maybe a))
-> Either [Char] (CellDecoder a)
-> Either [Char] (CellDecoder (Maybe a))
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CellDecoder a -> CellDecoder (Maybe a)
forall a. CellDecoder a -> CellDecoder (Maybe a)
nullableCell (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile TdsContext
ctx ColumnInfo
col)
{-# OPAQUE nullableField #-}
nullableCell :: CellDecoder a -> CellDecoder (Maybe a)
nullableCell :: forall a. CellDecoder a -> CellDecoder (Maybe a)
nullableCell (CellDecoder Either [Char] a
_ ValueReader a
borrowed ValueReader a
owned) =
Either [Char] (Maybe a)
-> ValueReader (Maybe a)
-> ValueReader (Maybe a)
-> CellDecoder (Maybe a)
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder (Maybe a -> Either [Char] (Maybe a)
forall a b. b -> Either a b
Right Maybe a
forall a. Maybe a
Nothing) ((a -> Maybe a) -> Either [Char] a -> Either [Char] (Maybe a)
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (Either [Char] a -> Either [Char] (Maybe a))
-> ValueReader a -> ValueReader (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
borrowed) ((a -> Maybe a) -> Either [Char] a -> Either [Char] (Maybe a)
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (Either [Char] a -> Either [Char] (Maybe a))
-> ValueReader a -> ValueReader (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
owned)
nullableCell (FoldingCell Either [Char] a
_ ValueReader a
borrowed ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold) =
Either [Char] (Maybe a)
-> ValueReader (Maybe a)
-> ValueReader (Maybe a)
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure (Maybe a)))
-> CellDecoder (Maybe a)
forall a.
Either [Char] a
-> ValueReader a
-> ValueReader a
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> CellDecoder a
FoldingCell (Maybe a -> Either [Char] (Maybe a)
forall a b. b -> Either a b
Right Maybe a
forall a. Maybe a
Nothing) ((a -> Maybe a) -> Either [Char] a -> Either [Char] (Maybe a)
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (Either [Char] a -> Either [Char] (Maybe a))
-> ValueReader a -> ValueReader (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
borrowed) ((a -> Maybe a) -> Either [Char] a -> Either [Char] (Maybe a)
forall a b. (a -> b) -> Either [Char] a -> Either [Char] b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just (Either [Char] a -> Either [Char] (Maybe a))
-> ValueReader a -> ValueReader (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
owned) ((Either ReadFailure a -> Either ReadFailure (Maybe a))
-> Parser (Either ReadFailure a)
-> Parser (Either ReadFailure (Maybe a))
forall a b. (a -> b) -> Recipe () a -> Recipe () b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> Maybe a)
-> Either ReadFailure a -> Either ReadFailure (Maybe a)
forall a b.
(a -> b) -> Either ReadFailure a -> Either ReadFailure b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just) (Parser (Either ReadFailure a)
-> Parser (Either ReadFailure (Maybe a)))
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure (Maybe a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold)
nullableCell (StreamingCell StreamedValue -> Parser (Either ReadFailure a)
d) = (StreamedValue -> Parser (Either ReadFailure (Maybe a)))
-> CellDecoder (Maybe a)
forall a.
(StreamedValue -> Parser (Either ReadFailure a)) -> CellDecoder a
StreamingCell ((StreamedValue -> Parser (Either ReadFailure (Maybe a)))
-> CellDecoder (Maybe a))
-> (StreamedValue -> Parser (Either ReadFailure (Maybe a)))
-> CellDecoder (Maybe a)
forall a b. (a -> b) -> a -> b
$ \case
StreamedValue
StreamedNull -> Either ReadFailure (Maybe a)
-> Parser (Either ReadFailure (Maybe a))
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe a -> Either ReadFailure (Maybe a)
forall a b. b -> Either a b
Right Maybe a
forall a. Maybe a
Nothing)
StreamedValue
cell -> (Either ReadFailure a -> Either ReadFailure (Maybe a))
-> Parser (Either ReadFailure a)
-> Parser (Either ReadFailure (Maybe a))
forall a b. (a -> b) -> Recipe () a -> Recipe () b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> Maybe a)
-> Either ReadFailure a -> Either ReadFailure (Maybe a)
forall a b.
(a -> b) -> Either ReadFailure a -> Either ReadFailure b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just) (StreamedValue -> Parser (Either ReadFailure a)
d StreamedValue
cell)
{-# INLINE nullableCell #-}
data Nulls a b where
NoNulls :: Nulls a a
Nulls :: Nulls a (Maybe a)
nullsField :: Nulls a b -> FieldDecoder a -> FieldDecoder b
nullsField :: forall a b. Nulls a b -> FieldDecoder a -> FieldDecoder b
nullsField Nulls a b
NoNulls = FieldDecoder a -> FieldDecoder a
FieldDecoder a -> FieldDecoder b
forall a. a -> a
id
nullsField Nulls a b
Nulls = FieldDecoder a -> FieldDecoder b
FieldDecoder a -> FieldDecoder (Maybe a)
forall a. FieldDecoder a -> FieldDecoder (Maybe a)
nullableField
{-# INLINE nullsField #-}
nullsCell :: Nulls a b -> CellDecoder a -> CellDecoder b
nullsCell :: forall a b. Nulls a b -> CellDecoder a -> CellDecoder b
nullsCell Nulls a b
NoNulls = CellDecoder a -> CellDecoder a
CellDecoder a -> CellDecoder b
forall a. a -> a
id
nullsCell Nulls a b
Nulls = CellDecoder a -> CellDecoder b
CellDecoder a -> CellDecoder (Maybe a)
forall a. CellDecoder a -> CellDecoder (Maybe a)
nullableCell
{-# NOINLINE nullsCell #-}
instance FromSqlField a => FromSqlField (Maybe a) where
fieldDecoder :: FieldDecoder (Maybe a)
fieldDecoder = FieldDecoder a -> FieldDecoder (Maybe a)
forall a. FieldDecoder a -> FieldDecoder (Maybe a)
nullableField FieldDecoder a
forall a. FromSqlField a => FieldDecoder a
fieldDecoder
fieldRowDecoder :: RowDecoder (Maybe a)
fieldRowDecoder = RowDecoder (Maybe a)
forall a. FromSqlField a => RowDecoder (Maybe a)
nullableRowDecoder
{-# INLINE fieldRowDecoder #-}
refineField :: (a -> Either String b) -> FieldDecoder a -> FieldDecoder b
refineField :: forall a b.
(a -> Either [Char] b) -> FieldDecoder a -> FieldDecoder b
refineField a -> Either [Char] b
f (FieldDecoder TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile) = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder b))
-> FieldDecoder b
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder b))
-> FieldDecoder b)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder b))
-> FieldDecoder b
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> do
d <- TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compile TdsContext
ctx ColumnInfo
col
let refined = ([Char] -> Either ReadFailure b)
-> (b -> Either ReadFailure b)
-> Either [Char] b
-> Either ReadFailure b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ReadFailure -> Either ReadFailure b
forall a b. a -> Either a b
Left (ReadFailure -> Either ReadFailure b)
-> ([Char] -> ReadFailure) -> [Char] -> Either ReadFailure b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DecodeError -> ReadFailure
DecodeFailed (DecodeError -> ReadFailure)
-> ([Char] -> DecodeError) -> [Char] -> ReadFailure
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col))) b -> Either ReadFailure b
forall a b. b -> Either a b
Right (Either [Char] b -> Either ReadFailure b)
-> (a -> Either [Char] b) -> a -> Either ReadFailure b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either [Char] b
f
pure $ case d of
CellDecoder Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned -> Either [Char] b -> ValueReader b -> ValueReader b -> CellDecoder b
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder (Either [Char] a
onNull Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] b
f)
(\ByteString
bytes -> ValueReader a
borrowed ByteString
bytes Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] b
f) (\ByteString
bytes -> ValueReader a
owned ByteString
bytes Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] b
f)
FoldingCell Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold -> Either [Char] b
-> ValueReader b
-> ValueReader b
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure b))
-> CellDecoder b
forall a.
Either [Char] a
-> ValueReader a
-> ValueReader a
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> CellDecoder a
FoldingCell (Either [Char] a
onNull Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] b
f)
(\ByteString
bytes -> ValueReader a
borrowed ByteString
bytes Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] b
f) (\ByteString
bytes -> ValueReader a
owned ByteString
bytes Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall a b.
Either [Char] a -> (a -> Either [Char] b) -> Either [Char] b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either [Char] b
f)
(\Stream (Of ByteString) (Recipe ()) ()
chunks -> (Either ReadFailure a
-> (a -> Either ReadFailure b) -> Either ReadFailure b
forall a b.
Either ReadFailure a
-> (a -> Either ReadFailure b) -> Either ReadFailure b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Either ReadFailure b
refined) (Either ReadFailure a -> Either ReadFailure b)
-> Parser (Either ReadFailure a) -> Parser (Either ReadFailure b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold Stream (Of ByteString) (Recipe ()) ()
chunks)
StreamingCell StreamedValue -> Parser (Either ReadFailure a)
read -> (StreamedValue -> Parser (Either ReadFailure b)) -> CellDecoder b
forall a.
(StreamedValue -> Parser (Either ReadFailure a)) -> CellDecoder a
StreamingCell ((StreamedValue -> Parser (Either ReadFailure b)) -> CellDecoder b)
-> (StreamedValue -> Parser (Either ReadFailure b))
-> CellDecoder b
forall a b. (a -> b) -> a -> b
$ \StreamedValue
cell -> do
result <- StreamedValue -> Parser (Either ReadFailure a)
read StreamedValue
cell
pure $ result >>= refined
{-# OPAQUE refineField #-}
newtype RawValue = RawValue B.ByteString deriving stock (RawValue -> RawValue -> Bool
(RawValue -> RawValue -> Bool)
-> (RawValue -> RawValue -> Bool) -> Eq RawValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RawValue -> RawValue -> Bool
== :: RawValue -> RawValue -> Bool
$c/= :: RawValue -> RawValue -> Bool
/= :: RawValue -> RawValue -> Bool
Eq, Int -> RawValue -> [Char] -> [Char]
[RawValue] -> [Char] -> [Char]
RawValue -> [Char]
(Int -> RawValue -> [Char] -> [Char])
-> (RawValue -> [Char])
-> ([RawValue] -> [Char] -> [Char])
-> Show RawValue
forall a.
(Int -> a -> [Char] -> [Char])
-> (a -> [Char]) -> ([a] -> [Char] -> [Char]) -> Show a
$cshowsPrec :: Int -> RawValue -> [Char] -> [Char]
showsPrec :: Int -> RawValue -> [Char] -> [Char]
$cshow :: RawValue -> [Char]
show :: RawValue -> [Char]
$cshowList :: [RawValue] -> [Char] -> [Char]
showList :: [RawValue] -> [Char] -> [Char]
Show)
rawValueDecoder :: FieldDecoder RawValue
rawValueDecoder :: FieldDecoder RawValue
rawValueDecoder = [Char]
-> (TypeInfo -> Bool)
-> (ByteString -> RawValue)
-> FieldDecoder RawValue
forall a.
[Char] -> (TypeInfo -> Bool) -> (ByteString -> a) -> FieldDecoder a
bytesDecoder [Char]
"RawValue" (Bool -> TypeInfo -> Bool
forall a b. a -> b -> a
const Bool
True) ByteString -> RawValue
RawValue
{-# INLINE rawValueDecoder #-}
instance FromSqlField RawValue where
fieldDecoder :: FieldDecoder RawValue
fieldDecoder = FieldDecoder RawValue
rawValueDecoder
rowDecoderWith :: forall b. Nulls RawValue b -> RowDecoder b
rowDecoderWith = FieldDecoder RawValue
-> FieldDecoder RawValue -> Nulls RawValue b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder RawValue
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder RawValue
rawValueDecoder
{-# NOINLINE rowDecoderWith #-}
boundedInteger :: forall a. (Integral a, Bounded a) => String -> FieldDecoder a
boundedInteger :: forall a. (Integral a, Bounded a) => [Char] -> FieldDecoder a
boundedInteger [Char]
name = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] Bool)
-> (Bool -> ValueReader a)
-> FieldDecoder a
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name TypeInfo -> Bool
isIntegerType (\TdsContext
_ TypeInfo
ti -> Bool -> Either [Char] Bool
forall a b. b -> Either a b
Right (TypeInfo -> Bool
unsignedByteType TypeInfo
ti)) ((Bool -> ValueReader a) -> FieldDecoder a)
-> (Bool -> ValueReader a) -> FieldDecoder a
forall a b. (a -> b) -> a -> b
$ \Bool
unsigned ByteString
bs ->
case Bool -> ValueReader Int64
integerAt Bool
unsigned ByteString
bs of
Left [Char]
e -> [Char] -> Either [Char] a
forall a b. a -> Either a b
Left [Char]
e
Right (I64# Int64#
i) -> [Char] -> Int64# -> Either [Char] a
forall a.
(Integral a, Bounded a) =>
[Char] -> Int64# -> Either [Char] a
inBounds [Char]
name Int64#
i
{-# INLINE boundedInteger #-}
inBounds :: forall a. (Integral a, Bounded a) => String -> Int64# -> Either String a
inBounds :: forall a.
(Integral a, Bounded a) =>
[Char] -> Int64# -> Either [Char] a
inBounds [Char]
name Int64#
i
| Int64# -> Int64
I64# Int64#
i Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< a -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
minBound @a) Bool -> Bool -> Bool
|| Int64# -> Int64
I64# Int64#
i Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
> a -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
maxBound @a) = [Char] -> Either [Char] a
forall a b. a -> Either a b
Left ([Char] -> Int64 -> [Char]
outOfRange [Char]
name (Int64# -> Int64
I64# Int64#
i))
| Bool
otherwise = a -> Either [Char] a
forall a b. b -> Either a b
Right (Int64 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64# -> Int64
I64# Int64#
i))
{-# INLINE inBounds #-}
outOfRange :: String -> Int64 -> String
outOfRange :: [Char] -> Int64 -> [Char]
outOfRange [Char]
name Int64
i = [Char]
"value " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int64 -> [Char]
forall a. Show a => a -> [Char]
show Int64
i [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" is out of range for " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
name
{-# NOINLINE outOfRange #-}
decimalReader :: DecimalColumn -> ValueReader Decimal
decimalReader :: DecimalColumn -> ValueReader Decimal
decimalReader DecimalColumn
column !ByteString
bs = case DecimalColumn
column of
DecimalColumn Word8
precision Word8
scale -> Word8 -> Word8 -> ValueReader Decimal
readDecimal Word8
precision Word8
scale ByteString
bs
OtherDecimal TypeInfo
ti -> TypeInfo -> ValueReader Decimal
decimalValue TypeInfo
ti ByteString
bs
{-# NOINLINE decimalReader #-}
data DecimalColumn = DecimalColumn Precision Scale | OtherDecimal TypeInfo
decimalColumn :: TypeInfo -> DecimalColumn
decimalColumn :: TypeInfo -> DecimalColumn
decimalColumn = \case
TIDecimalN Word8
precision Word8
scale -> Word8 -> Word8 -> DecimalColumn
DecimalColumn Word8
precision Word8
scale
TINumericN Word8
precision Word8
scale -> Word8 -> Word8 -> DecimalColumn
DecimalColumn Word8
precision Word8
scale
TypeInfo
ti -> TypeInfo -> DecimalColumn
OtherDecimal TypeInfo
ti
moneyValue :: ValueReader Money
moneyValue :: ValueReader Money
moneyValue !ByteString
bs = ValueReader Money
readMoney ByteString
bs
{-# NOINLINE moneyValue #-}
localTimeReader :: TypeInfo -> ValueReader LocalTime
localTimeReader :: TypeInfo -> ValueReader LocalTime
localTimeReader TypeInfo
ti !ByteString
bs = TypeInfo -> ValueReader LocalTime
localTimeValue TypeInfo
ti ByteString
bs
{-# NOINLINE localTimeReader #-}
utcTimeReader :: TypeInfo -> ValueReader UTCTime
utcTimeReader :: TypeInfo -> ValueReader UTCTime
utcTimeReader TypeInfo
ti !ByteString
bs = case TypeInfo
ti of
TIDateTimeOffsetN Word8
s -> DateTimeOffset -> UTCTime
dtoUtcTime (DateTimeOffset -> UTCTime)
-> Either [Char] DateTimeOffset -> Either [Char] UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word8 -> ValueReader DateTimeOffset
readDateTimeOffset Word8
s ByteString
bs
TypeInfo
_ -> (Day -> Int64 -> UTCTime) -> TypeInfo -> ValueReader UTCTime
forall a. (Day -> Int64 -> a) -> TypeInfo -> ValueReader a
dayTimeValue Day -> Int64 -> UTCTime
utcTimeOf TypeInfo
ti ByteString
bs
{-# NOINLINE utcTimeReader #-}
dayValue :: ValueReader Day
dayValue :: ValueReader Day
dayValue !ByteString
bs = ValueReader Day
readDate ByteString
bs
{-# NOINLINE dayValue #-}
intDecoder :: FieldDecoder Int
intDecoder :: FieldDecoder Int
intDecoder = [Char] -> FieldDecoder Int
forall a. (Integral a, Bounded a) => [Char] -> FieldDecoder a
boundedInteger [Char]
"Int"
{-# INLINE intDecoder #-}
instance FromSqlField Int where
fieldDecoder :: FieldDecoder Int
fieldDecoder = FieldDecoder Int
intDecoder
rowDecoderWith :: forall b. Nulls Int b -> RowDecoder b
rowDecoderWith = FieldDecoder Int -> FieldDecoder Int -> Nulls Int b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Int
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Int
intDecoder
{-# NOINLINE rowDecoderWith #-}
int8Decoder :: FieldDecoder Int8
int8Decoder :: FieldDecoder Int8
int8Decoder = [Char] -> FieldDecoder Int8
forall a. (Integral a, Bounded a) => [Char] -> FieldDecoder a
boundedInteger [Char]
"Int8"
{-# INLINE int8Decoder #-}
instance FromSqlField Int8 where
fieldDecoder :: FieldDecoder Int8
fieldDecoder = FieldDecoder Int8
int8Decoder
rowDecoderWith :: forall b. Nulls Int8 b -> RowDecoder b
rowDecoderWith = FieldDecoder Int8
-> FieldDecoder Int8 -> Nulls Int8 b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Int8
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Int8
int8Decoder
{-# NOINLINE rowDecoderWith #-}
int16Decoder :: FieldDecoder Int16
int16Decoder :: FieldDecoder Int16
int16Decoder = [Char] -> FieldDecoder Int16
forall a. (Integral a, Bounded a) => [Char] -> FieldDecoder a
boundedInteger [Char]
"Int16"
{-# INLINE int16Decoder #-}
instance FromSqlField Int16 where
fieldDecoder :: FieldDecoder Int16
fieldDecoder = FieldDecoder Int16
int16Decoder
rowDecoderWith :: forall b. Nulls Int16 b -> RowDecoder b
rowDecoderWith = FieldDecoder Int16
-> FieldDecoder Int16 -> Nulls Int16 b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Int16
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Int16
int16Decoder
{-# NOINLINE rowDecoderWith #-}
int32Decoder :: FieldDecoder Int32
int32Decoder :: FieldDecoder Int32
int32Decoder = [Char] -> FieldDecoder Int32
forall a. (Integral a, Bounded a) => [Char] -> FieldDecoder a
boundedInteger [Char]
"Int32"
{-# INLINE int32Decoder #-}
instance FromSqlField Int32 where
fieldDecoder :: FieldDecoder Int32
fieldDecoder = FieldDecoder Int32
int32Decoder
rowDecoderWith :: forall b. Nulls Int32 b -> RowDecoder b
rowDecoderWith = FieldDecoder Int32
-> FieldDecoder Int32 -> Nulls Int32 b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Int32
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Int32
int32Decoder
{-# NOINLINE rowDecoderWith #-}
int64Decoder :: FieldDecoder Int64
int64Decoder :: FieldDecoder Int64
int64Decoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] Bool)
-> (Bool -> ValueReader Int64)
-> FieldDecoder Int64
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Int64" TypeInfo -> Bool
isIntegerType (\TdsContext
_ TypeInfo
ti -> Bool -> Either [Char] Bool
forall a b. b -> Either a b
Right (TypeInfo -> Bool
unsignedByteType TypeInfo
ti)) Bool -> ValueReader Int64
integerAt
{-# INLINE int64Decoder #-}
instance FromSqlField Int64 where
fieldDecoder :: FieldDecoder Int64
fieldDecoder = FieldDecoder Int64
int64Decoder
rowDecoderWith :: forall b. Nulls Int64 b -> RowDecoder b
rowDecoderWith = FieldDecoder Int64
-> FieldDecoder Int64 -> Nulls Int64 b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Int64
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Int64
int64Decoder
{-# NOINLINE rowDecoderWith #-}
word8Decoder :: FieldDecoder Word8
word8Decoder :: FieldDecoder Word8
word8Decoder = [Char] -> FieldDecoder Word8
forall a. (Integral a, Bounded a) => [Char] -> FieldDecoder a
boundedInteger [Char]
"Word8"
{-# INLINE word8Decoder #-}
instance FromSqlField Word8 where
fieldDecoder :: FieldDecoder Word8
fieldDecoder = FieldDecoder Word8
word8Decoder
rowDecoderWith :: forall b. Nulls Word8 b -> RowDecoder b
rowDecoderWith = FieldDecoder Word8
-> FieldDecoder Word8 -> Nulls Word8 b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Word8
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Word8
word8Decoder
{-# NOINLINE rowDecoderWith #-}
instance FromSqlField Integer where
fieldDecoder :: FieldDecoder Integer
fieldDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] TypeInfo)
-> (TypeInfo -> ValueReader Integer)
-> FieldDecoder Integer
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Integer" (\TypeInfo
ti -> TypeInfo -> Bool
isIntegerType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isScale0 TypeInfo
ti) (\TdsContext
_ TypeInfo
ti -> TypeInfo -> Either [Char] TypeInfo
forall a b. b -> Either a b
Right TypeInfo
ti) ((TypeInfo -> ValueReader Integer) -> FieldDecoder Integer)
-> (TypeInfo -> ValueReader Integer) -> FieldDecoder Integer
forall a b. (a -> b) -> a -> b
$ \TypeInfo
ti ByteString
bs ->
if TypeInfo -> Bool
isScale0 TypeInfo
ti
then Decimal -> Integer
forall i. DecimalRaw i -> i
decimalMantissa (Decimal -> Integer)
-> Either [Char] Decimal -> Either [Char] Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TypeInfo -> ValueReader Decimal
decimalValue TypeInfo
ti ByteString
bs
else Int64 -> Integer
forall a. Integral a => a -> Integer
toInteger (Int64 -> Integer) -> Either [Char] Int64 -> Either [Char] Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TypeInfo -> ValueReader Int64
integerValue TypeInfo
ti ByteString
bs
where
isScale0 :: TypeInfo -> Bool
isScale0 = \case
TIDecimalN Word8
_ Word8
0 -> Bool
True
TINumericN Word8
_ Word8
0 -> Bool
True
TypeInfo
_ -> Bool
False
boolDecoder :: FieldDecoder Bool
boolDecoder :: FieldDecoder Bool
boolDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] ())
-> (() -> ValueReader Bool)
-> FieldDecoder Bool
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Bool" ((SqlDataType -> Bool) -> TypeInfo -> Bool
hasDataType (SqlDataType -> SqlDataType -> Bool
forall a. Eq a => a -> a -> Bool
== SqlDataType
TyBit)) (\TdsContext
_ TypeInfo
_ -> () -> Either [Char] ()
forall a b. b -> Either a b
Right ()) (\()
_ -> ValueReader Bool
bitValue)
{-# INLINE boolDecoder #-}
instance FromSqlField Bool where
fieldDecoder :: FieldDecoder Bool
fieldDecoder = FieldDecoder Bool
boolDecoder
rowDecoderWith :: forall b. Nulls Bool b -> RowDecoder b
rowDecoderWith = FieldDecoder Bool
-> FieldDecoder Bool -> Nulls Bool b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Bool
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Bool
boolDecoder
{-# NOINLINE rowDecoderWith #-}
doubleDecoder :: FieldDecoder Double
doubleDecoder :: FieldDecoder Double
doubleDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] ())
-> (() -> ValueReader Double)
-> FieldDecoder Double
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Double" TypeInfo -> Bool
isFloatType (\TdsContext
_ TypeInfo
_ -> () -> Either [Char] ()
forall a b. b -> Either a b
Right ()) (\()
_ -> ValueReader Double
readFloating)
{-# INLINE doubleDecoder #-}
instance FromSqlField Double where
fieldDecoder :: FieldDecoder Double
fieldDecoder = FieldDecoder Double
doubleDecoder
rowDecoderWith :: forall b. Nulls Double b -> RowDecoder b
rowDecoderWith = FieldDecoder Double
-> FieldDecoder Double -> Nulls Double b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Double
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Double
doubleDecoder
{-# NOINLINE rowDecoderWith #-}
floatDecoder :: FieldDecoder Float
floatDecoder :: FieldDecoder Float
floatDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] ())
-> (() -> ValueReader Float)
-> FieldDecoder Float
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Float" TypeInfo -> Bool
isFloatType (\TdsContext
_ TypeInfo
_ -> () -> Either [Char] ()
forall a b. b -> Either a b
Right ()) (\()
_ -> ValueReader Float
float32Value)
{-# INLINE floatDecoder #-}
instance FromSqlField Float where
fieldDecoder :: FieldDecoder Float
fieldDecoder = FieldDecoder Float
floatDecoder
rowDecoderWith :: forall b. Nulls Float b -> RowDecoder b
rowDecoderWith = FieldDecoder Float
-> FieldDecoder Float -> Nulls Float b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Float
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Float
floatDecoder
{-# NOINLINE rowDecoderWith #-}
decimalDecoder :: FieldDecoder Decimal
decimalDecoder :: FieldDecoder Decimal
decimalDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] DecimalColumn)
-> (DecimalColumn -> ValueReader Decimal)
-> FieldDecoder Decimal
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Decimal"
(\TypeInfo
ti -> TypeInfo -> Bool
isDecimalType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isMoneyType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isIntegerType TypeInfo
ti)
(\TdsContext
_ TypeInfo
ti -> DecimalColumn -> Either [Char] DecimalColumn
forall a b. b -> Either a b
Right (TypeInfo -> DecimalColumn
decimalColumn TypeInfo
ti))
DecimalColumn -> ValueReader Decimal
decimalReader
{-# INLINE decimalDecoder #-}
instance FromSqlField Decimal where
fieldDecoder :: FieldDecoder Decimal
fieldDecoder = FieldDecoder Decimal
decimalDecoder
rowDecoderWith :: forall b. Nulls Decimal b -> RowDecoder b
rowDecoderWith = FieldDecoder Decimal
-> FieldDecoder Decimal -> Nulls Decimal b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Decimal
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Decimal
decimalDecoder
{-# NOINLINE rowDecoderWith #-}
moneyDecoder :: FieldDecoder Money
moneyDecoder :: FieldDecoder Money
moneyDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] ())
-> (() -> ValueReader Money)
-> FieldDecoder Money
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Money" TypeInfo -> Bool
isMoneyType (\TdsContext
_ TypeInfo
_ -> () -> Either [Char] ()
forall a b. b -> Either a b
Right ()) (\()
_ -> ValueReader Money
moneyValue)
{-# INLINE moneyDecoder #-}
instance FromSqlField Money where
fieldDecoder :: FieldDecoder Money
fieldDecoder = FieldDecoder Money
moneyDecoder
rowDecoderWith :: forall b. Nulls Money b -> RowDecoder b
rowDecoderWith = FieldDecoder Money
-> FieldDecoder Money -> Nulls Money b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Money
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Money
moneyDecoder
{-# NOINLINE rowDecoderWith #-}
uuidDecoder :: FieldDecoder UUID
uuidDecoder :: FieldDecoder UUID
uuidDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] ())
-> (() -> ValueReader UUID)
-> FieldDecoder UUID
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"UUID" ((SqlDataType -> Bool) -> TypeInfo -> Bool
hasDataType (SqlDataType -> SqlDataType -> Bool
forall a. Eq a => a -> a -> Bool
== SqlDataType
TyUniqueIdentifier)) (\TdsContext
_ TypeInfo
_ -> () -> Either [Char] ()
forall a b. b -> Either a b
Right ()) (\()
_ -> ValueReader UUID
readGuid)
{-# INLINE uuidDecoder #-}
instance FromSqlField UUID where
fieldDecoder :: FieldDecoder UUID
fieldDecoder = FieldDecoder UUID
uuidDecoder
rowDecoderWith :: forall b. Nulls UUID b -> RowDecoder b
rowDecoderWith = FieldDecoder UUID
-> FieldDecoder UUID -> Nulls UUID b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder UUID
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder UUID
uuidDecoder
{-# NOINLINE rowDecoderWith #-}
textDecoder :: FieldDecoder Text
textDecoder :: FieldDecoder Text
textDecoder = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder Text))
-> FieldDecoder Text
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder Text))
-> FieldDecoder Text)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder Text))
-> FieldDecoder Text
forall a b. (a -> b) -> a -> b
$ \TdsContext
_ ColumnInfo
col -> do
enc <- TypeInfo -> Either [Char] TextEncoding
textEncodingOf (ColumnInfo -> TypeInfo
columnType ColumnInfo
col)
let read = TextEncoding -> ValueReader Text
textValue TextEncoding
enc
pure (CellDecoder (nullAs "Text") read read)
{-# INLINE textDecoder #-}
instance FromSqlField Text where
fieldDecoder :: FieldDecoder Text
fieldDecoder = FieldDecoder Text
textDecoder
rowDecoderWith :: forall b. Nulls Text b -> RowDecoder b
rowDecoderWith = FieldDecoder Text
-> FieldDecoder Text -> Nulls Text b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Text
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Text
textDecoder
{-# NOINLINE rowDecoderWith #-}
lazyTextDecoder :: FieldDecoder LT.Text
lazyTextDecoder :: FieldDecoder Text
lazyTextDecoder = Text -> Text
LT.fromStrict (Text -> Text) -> FieldDecoder Text -> FieldDecoder Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldDecoder Text
textDecoder
{-# INLINE lazyTextDecoder #-}
instance FromSqlField LT.Text where
fieldDecoder :: FieldDecoder Text
fieldDecoder = FieldDecoder Text
lazyTextDecoder
rowDecoderWith :: forall b. Nulls Text b -> RowDecoder b
rowDecoderWith = FieldDecoder Text
-> FieldDecoder Text -> Nulls Text b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Text
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Text
lazyTextDecoder
{-# NOINLINE rowDecoderWith #-}
stringDecoder :: FieldDecoder String
stringDecoder :: FieldDecoder [Char]
stringDecoder = Text -> [Char]
T.unpack (Text -> [Char]) -> FieldDecoder Text -> FieldDecoder [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldDecoder Text
textDecoder
{-# INLINE stringDecoder #-}
instance {-# OVERLAPPING #-} FromSqlField String where
fieldDecoder :: FieldDecoder [Char]
fieldDecoder = FieldDecoder [Char]
stringDecoder
rowDecoderWith :: forall b. Nulls [Char] b -> RowDecoder b
rowDecoderWith = FieldDecoder [Char]
-> FieldDecoder [Char] -> Nulls [Char] b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder [Char]
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder [Char]
stringDecoder
{-# NOINLINE rowDecoderWith #-}
byteStringDecoder :: FieldDecoder B.ByteString
byteStringDecoder :: FieldDecoder ByteString
byteStringDecoder = [Char]
-> (TypeInfo -> Bool)
-> (ByteString -> ByteString)
-> FieldDecoder ByteString
forall a.
[Char] -> (TypeInfo -> Bool) -> (ByteString -> a) -> FieldDecoder a
bytesDecoder [Char]
"ByteString" (\TypeInfo
ti -> TypeInfo -> Bool
isBinaryType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isAnsiType TypeInfo
ti) ByteString -> ByteString
forall a. a -> a
id
{-# INLINE byteStringDecoder #-}
instance FromSqlField B.ByteString where
fieldDecoder :: FieldDecoder ByteString
fieldDecoder = FieldDecoder ByteString
byteStringDecoder
rowDecoderWith :: forall b. Nulls ByteString b -> RowDecoder b
rowDecoderWith = FieldDecoder ByteString
-> FieldDecoder ByteString -> Nulls ByteString b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder ByteString
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder ByteString
byteStringDecoder
{-# NOINLINE rowDecoderWith #-}
lazyByteStringDecoder :: FieldDecoder LB.ByteString
lazyByteStringDecoder :: FieldDecoder ByteString
lazyByteStringDecoder = ByteString -> ByteString
LB.fromStrict (ByteString -> ByteString)
-> FieldDecoder ByteString -> FieldDecoder ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldDecoder ByteString
byteStringDecoder
{-# INLINE lazyByteStringDecoder #-}
instance FromSqlField LB.ByteString where
fieldDecoder :: FieldDecoder ByteString
fieldDecoder = FieldDecoder ByteString
lazyByteStringDecoder
rowDecoderWith :: forall b. Nulls ByteString b -> RowDecoder b
rowDecoderWith = FieldDecoder ByteString
-> FieldDecoder ByteString -> Nulls ByteString b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder ByteString
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder ByteString
lazyByteStringDecoder
{-# NOINLINE rowDecoderWith #-}
localTimeDecoder :: FieldDecoder LocalTime
localTimeDecoder :: FieldDecoder LocalTime
localTimeDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] TypeInfo)
-> (TypeInfo -> ValueReader LocalTime)
-> FieldDecoder LocalTime
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"LocalTime" TypeInfo -> Bool
isLocalTimeType (\TdsContext
_ TypeInfo
ti -> TypeInfo -> Either [Char] TypeInfo
forall a b. b -> Either a b
Right TypeInfo
ti) TypeInfo -> ValueReader LocalTime
localTimeReader
{-# INLINE localTimeDecoder #-}
instance FromSqlField LocalTime where
fieldDecoder :: FieldDecoder LocalTime
fieldDecoder = FieldDecoder LocalTime
localTimeDecoder
rowDecoderWith :: forall b. Nulls LocalTime b -> RowDecoder b
rowDecoderWith = FieldDecoder LocalTime
-> FieldDecoder LocalTime -> Nulls LocalTime b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder LocalTime
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder LocalTime
localTimeDecoder
{-# NOINLINE rowDecoderWith #-}
utcTimeDecoder :: FieldDecoder UTCTime
utcTimeDecoder :: FieldDecoder UTCTime
utcTimeDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] TypeInfo)
-> (TypeInfo -> ValueReader UTCTime)
-> FieldDecoder UTCTime
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"UTCTime"
(\TypeInfo
ti -> TypeInfo -> Bool
isLocalTimeType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isDateTimeOffsetType TypeInfo
ti)
(\TdsContext
_ TypeInfo
ti -> TypeInfo -> Either [Char] TypeInfo
forall a b. b -> Either a b
Right TypeInfo
ti)
TypeInfo -> ValueReader UTCTime
utcTimeReader
{-# INLINE utcTimeDecoder #-}
instance FromSqlField UTCTime where
fieldDecoder :: FieldDecoder UTCTime
fieldDecoder = FieldDecoder UTCTime
utcTimeDecoder
rowDecoderWith :: forall b. Nulls UTCTime b -> RowDecoder b
rowDecoderWith = FieldDecoder UTCTime
-> FieldDecoder UTCTime -> Nulls UTCTime b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder UTCTime
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder UTCTime
utcTimeDecoder
{-# NOINLINE rowDecoderWith #-}
dateTimeOffsetDecoder :: FieldDecoder DateTimeOffset
dateTimeOffsetDecoder :: FieldDecoder DateTimeOffset
dateTimeOffsetDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] Word8)
-> (Word8 -> ValueReader DateTimeOffset)
-> FieldDecoder DateTimeOffset
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"DateTimeOffset" TypeInfo -> Bool
isDateTimeOffsetType
(\TdsContext
_ TypeInfo
ti -> case TypeInfo
ti of
TIDateTimeOffsetN Word8
s -> Word8 -> Either [Char] Word8
forall a b. b -> Either a b
Right Word8
s
TypeInfo
_ -> [Char] -> Either [Char] Word8
forall a b. a -> Either a b
Left [Char]
"not datetimeoffset")
Word8 -> ValueReader DateTimeOffset
readDateTimeOffset
{-# INLINE dateTimeOffsetDecoder #-}
instance FromSqlField DateTimeOffset where
fieldDecoder :: FieldDecoder DateTimeOffset
fieldDecoder = FieldDecoder DateTimeOffset
dateTimeOffsetDecoder
rowDecoderWith :: forall b. Nulls DateTimeOffset b -> RowDecoder b
rowDecoderWith = FieldDecoder DateTimeOffset
-> FieldDecoder DateTimeOffset
-> Nulls DateTimeOffset b
-> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder DateTimeOffset
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder DateTimeOffset
dateTimeOffsetDecoder
{-# NOINLINE rowDecoderWith #-}
zonedTimeDecoder :: FieldDecoder ZonedTime
zonedTimeDecoder :: FieldDecoder ZonedTime
zonedTimeDecoder = DateTimeOffset -> ZonedTime
dateTimeOffsetToZonedTime (DateTimeOffset -> ZonedTime)
-> FieldDecoder DateTimeOffset -> FieldDecoder ZonedTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldDecoder DateTimeOffset
dateTimeOffsetDecoder
{-# INLINE zonedTimeDecoder #-}
instance FromSqlField ZonedTime where
fieldDecoder :: FieldDecoder ZonedTime
fieldDecoder = FieldDecoder ZonedTime
zonedTimeDecoder
rowDecoderWith :: forall b. Nulls ZonedTime b -> RowDecoder b
rowDecoderWith = FieldDecoder ZonedTime
-> FieldDecoder ZonedTime -> Nulls ZonedTime b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder ZonedTime
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder ZonedTime
zonedTimeDecoder
{-# NOINLINE rowDecoderWith #-}
dayDecoder :: FieldDecoder Day
dayDecoder :: FieldDecoder Day
dayDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] ())
-> (() -> ValueReader Day)
-> FieldDecoder Day
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"Day" ((SqlDataType -> Bool) -> TypeInfo -> Bool
hasDataType (SqlDataType -> SqlDataType -> Bool
forall a. Eq a => a -> a -> Bool
== SqlDataType
TyDate)) (\TdsContext
_ TypeInfo
_ -> () -> Either [Char] ()
forall a b. b -> Either a b
Right ()) (\()
_ -> ValueReader Day
dayValue)
{-# INLINE dayDecoder #-}
instance FromSqlField Day where
fieldDecoder :: FieldDecoder Day
fieldDecoder = FieldDecoder Day
dayDecoder
rowDecoderWith :: forall b. Nulls Day b -> RowDecoder b
rowDecoderWith = FieldDecoder Day -> FieldDecoder Day -> Nulls Day b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder Day
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder Day
dayDecoder
{-# NOINLINE rowDecoderWith #-}
timeOfDayDecoder :: FieldDecoder TimeOfDay
timeOfDayDecoder :: FieldDecoder TimeOfDay
timeOfDayDecoder = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] Word8)
-> (Word8 -> ValueReader TimeOfDay)
-> FieldDecoder TimeOfDay
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
"TimeOfDay" ((SqlDataType -> Bool) -> TypeInfo -> Bool
hasDataType (SqlDataType -> SqlDataType -> Bool
forall a. Eq a => a -> a -> Bool
== SqlDataType
TyTime))
(\TdsContext
_ TypeInfo
ti -> case TypeInfo
ti of
TITimeN Word8
s -> Word8 -> Either [Char] Word8
forall a b. b -> Either a b
Right Word8
s
TypeInfo
_ -> [Char] -> Either [Char] Word8
forall a b. a -> Either a b
Left [Char]
"not time")
Word8 -> ValueReader TimeOfDay
readTime
{-# INLINE timeOfDayDecoder #-}
instance FromSqlField TimeOfDay where
fieldDecoder :: FieldDecoder TimeOfDay
fieldDecoder = FieldDecoder TimeOfDay
timeOfDayDecoder
rowDecoderWith :: forall b. Nulls TimeOfDay b -> RowDecoder b
rowDecoderWith = FieldDecoder TimeOfDay
-> FieldDecoder TimeOfDay -> Nulls TimeOfDay b -> RowDecoder b
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder TimeOfDay
forall a. FromSqlField a => FieldDecoder a
fieldDecoder FieldDecoder TimeOfDay
timeOfDayDecoder
{-# NOINLINE rowDecoderWith #-}
dayTimeFieldDecoder :: String -> (Day -> Int64 -> a) -> FieldDecoder a
dayTimeFieldDecoder :: forall a. [Char] -> (Day -> Int64 -> a) -> FieldDecoder a
dayTimeFieldDecoder [Char]
name Day -> Int64 -> a
k = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] TypeInfo)
-> (TypeInfo -> ValueReader a)
-> FieldDecoder a
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name TypeInfo -> Bool
isLocalTimeType (\TdsContext
_ TypeInfo
ti -> TypeInfo -> Either [Char] TypeInfo
forall a b. b -> Either a b
Right TypeInfo
ti) ((Day -> Int64 -> a) -> TypeInfo -> ValueReader a
forall a. (Day -> Int64 -> a) -> TypeInfo -> ValueReader a
dayTimeValue Day -> Int64 -> a
k)
{-# INLINE dayTimeFieldDecoder #-}
dateTimeOffsetFieldDecoder :: String -> (Day -> Int64 -> Int16 -> a) -> FieldDecoder a
dateTimeOffsetFieldDecoder :: forall a. [Char] -> (Day -> Int64 -> Int16 -> a) -> FieldDecoder a
dateTimeOffsetFieldDecoder [Char]
name Day -> Int64 -> Int16 -> a
k = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] Word8)
-> (Word8 -> ValueReader a)
-> FieldDecoder a
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name TypeInfo -> Bool
isDateTimeOffsetType
(\TdsContext
_ TypeInfo
ti -> case TypeInfo
ti of
TIDateTimeOffsetN Word8
s -> Word8 -> Either [Char] Word8
forall a b. b -> Either a b
Right Word8
s
TypeInfo
_ -> [Char] -> Either [Char] Word8
forall a b. a -> Either a b
Left [Char]
"not datetimeoffset")
((Day -> Int64 -> Int16 -> a) -> Word8 -> ValueReader a
forall a. (Day -> Int64 -> Int16 -> a) -> Word8 -> ValueReader a
readDateTimeOffsetWith Day -> Int64 -> Int16 -> a
k)
{-# INLINE dateTimeOffsetFieldDecoder #-}
timeFieldDecoder :: String -> (Int64 -> a) -> FieldDecoder a
timeFieldDecoder :: forall a. [Char] -> (Int64 -> a) -> FieldDecoder a
timeFieldDecoder [Char]
name Int64 -> a
k = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] Word8)
-> (Word8 -> ValueReader a)
-> FieldDecoder a
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name ((SqlDataType -> Bool) -> TypeInfo -> Bool
hasDataType (SqlDataType -> SqlDataType -> Bool
forall a. Eq a => a -> a -> Bool
== SqlDataType
TyTime))
(\TdsContext
_ TypeInfo
ti -> case TypeInfo
ti of
TITimeN Word8
s -> Word8 -> Either [Char] Word8
forall a b. b -> Either a b
Right Word8
s
TypeInfo
_ -> [Char] -> Either [Char] Word8
forall a b. a -> Either a b
Left [Char]
"not time")
((Int64 -> a) -> Word8 -> ValueReader a
forall a. (Int64 -> a) -> Word8 -> ValueReader a
readTimeWith Int64 -> a
k)
{-# INLINE timeFieldDecoder #-}
decimalFieldDecoder :: String -> (Bool -> Word64 -> Word64 -> Word8 -> a) -> FieldDecoder a
decimalFieldDecoder :: forall a.
[Char]
-> (Bool -> Word64 -> Word64 -> Word8 -> a) -> FieldDecoder a
decimalFieldDecoder [Char]
name Bool -> Word64 -> Word64 -> Word8 -> a
k = [Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] DecimalColumn)
-> (DecimalColumn -> ValueReader a)
-> FieldDecoder a
forall s a.
[Char]
-> (TypeInfo -> Bool)
-> (TdsContext -> TypeInfo -> Either [Char] s)
-> (s -> ValueReader a)
-> FieldDecoder a
compiledFieldDecoder [Char]
name
(\TypeInfo
ti -> TypeInfo -> Bool
isDecimalType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isMoneyType TypeInfo
ti Bool -> Bool -> Bool
|| TypeInfo -> Bool
isIntegerType TypeInfo
ti)
(\TdsContext
_ TypeInfo
ti -> DecimalColumn -> Either [Char] DecimalColumn
forall a b. b -> Either a b
Right (TypeInfo -> DecimalColumn
decimalColumn TypeInfo
ti))
((Bool -> Word64 -> Word64 -> Word8 -> a)
-> DecimalColumn -> ValueReader a
forall a.
(Bool -> Word64 -> Word64 -> Word8 -> a)
-> DecimalColumn -> ValueReader a
decimalPartsReader Bool -> Word64 -> Word64 -> Word8 -> a
k)
{-# INLINE decimalFieldDecoder #-}
decimalPartsReader :: (Bool -> Word64 -> Word64 -> Word8 -> a) -> DecimalColumn -> ValueReader a
decimalPartsReader :: forall a.
(Bool -> Word64 -> Word64 -> Word8 -> a)
-> DecimalColumn -> ValueReader a
decimalPartsReader Bool -> Word64 -> Word64 -> Word8 -> a
k DecimalColumn
column !ByteString
bs = case DecimalColumn
column of
DecimalColumn Word8
precision Word8
scale -> (Bool -> Word64 -> Word64 -> Word8 -> a)
-> Word8 -> Word8 -> ValueReader a
forall a.
(Bool -> Word64 -> Word64 -> Word8 -> a)
-> Word8 -> Word8 -> ValueReader a
readDecimalWith Bool -> Word64 -> Word64 -> Word8 -> a
k Word8
precision Word8
scale ByteString
bs
OtherDecimal TypeInfo
ti
| TypeInfo -> Bool
isMoneyType TypeInfo
ti -> (Int64 -> Word8 -> Either [Char] a
`signed` Word8
4) (Int64 -> Either [Char] a)
-> Either [Char] Int64 -> Either [Char] a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ValueReader Int64
moneyUnits ByteString
bs
| Bool
otherwise -> (Int64 -> Word8 -> Either [Char] a
`signed` Word8
0) (Int64 -> Either [Char] a)
-> Either [Char] Int64 -> Either [Char] a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TypeInfo -> ValueReader Int64
integerValue TypeInfo
ti ByteString
bs
where
signed :: Int64 -> Word8 -> Either [Char] a
signed Int64
i Word8
scale = a -> Either [Char] a
forall a b. b -> Either a b
Right (a -> Either [Char] a) -> a -> Either [Char] a
forall a b. (a -> b) -> a -> b
$! Bool -> Word64 -> Word64 -> Word8 -> a
k (Int64
i Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< Int64
0) Word64
0 (if Int64
i Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< Int64
0 then Word64 -> Word64
forall a. Num a => a -> a
negate (Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
i) else Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
i) Word8
scale
{-# INLINE decimalPartsReader #-}
sqlValueDecoder :: FieldDecoder SqlValue
sqlValueDecoder :: FieldDecoder SqlValue
sqlValueDecoder = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder SqlValue))
-> FieldDecoder SqlValue
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder SqlValue))
-> FieldDecoder SqlValue)
-> (TdsContext
-> ColumnInfo -> Either [Char] (CellDecoder SqlValue))
-> FieldDecoder SqlValue
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> do
let ti :: TypeInfo
ti = ColumnInfo -> TypeInfo
columnType ColumnInfo
col
Bool -> Either [Char] () -> Either [Char] ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TypeInfo -> Bool
isAnsiType TypeInfo
ti) (Either [Char] () -> Either [Char] ())
-> Either [Char] () -> Either [Char] ()
forall a b. (a -> b) -> a -> b
$ () () -> Either [Char] (ValueReader Text) -> Either [Char] ()
forall a b. a -> Either [Char] b -> Either [Char] a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TypeInfo -> Either [Char] (ValueReader Text)
columnTextDecoder TypeInfo
ti
case TypeInfo
ti of
TIUdt UdtInfo
_ -> [Char] -> Either [Char] ()
forall a b. a -> Either a b
Left (TypeInfo -> [Char] -> [Char]
unsupportedUdt TypeInfo
ti [Char]
"as SqlValue")
TypeInfo
_ -> () -> Either [Char] ()
forall a. a -> Either [Char] a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
CellDecoder SqlValue -> Either [Char] (CellDecoder SqlValue)
forall a b. b -> Either a b
Right (CellDecoder SqlValue -> Either [Char] (CellDecoder SqlValue))
-> CellDecoder SqlValue -> Either [Char] (CellDecoder SqlValue)
forall a b. (a -> b) -> a -> b
$ if TypeInfo -> Bool
isBinaryType TypeInfo
ti
then Either [Char] SqlValue
-> ValueReader SqlValue
-> ValueReader SqlValue
-> CellDecoder SqlValue
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder (SqlValue -> Either [Char] SqlValue
forall a b. b -> Either a b
Right SqlValue
SqlNull)
(\ByteString
bytes -> SqlValue -> Either [Char] SqlValue
forall a b. b -> Either a b
Right (SqlValue -> Either [Char] SqlValue)
-> SqlValue -> Either [Char] SqlValue
forall a b. (a -> b) -> a -> b
$! ByteString -> SqlValue
SqlBinary (ByteString -> ByteString
B.copy ByteString
bytes)) (\ByteString
bytes -> SqlValue -> Either [Char] SqlValue
forall a b. b -> Either a b
Right (SqlValue -> Either [Char] SqlValue)
-> SqlValue -> Either [Char] SqlValue
forall a b. (a -> b) -> a -> b
$! ByteString -> SqlValue
SqlBinary ByteString
bytes)
else case TdsContext -> TypeInfo -> SelectedReader
selectSqlValueReader TdsContext
ctx TypeInfo
ti of
SelectedReader ValueReader SqlValue
reader -> Either [Char] SqlValue
-> ValueReader SqlValue -> CellDecoder SqlValue
forall a. Either [Char] a -> ValueReader a -> CellDecoder a
cellDecoder (SqlValue -> Either [Char] SqlValue
forall a b. b -> Either a b
Right SqlValue
SqlNull) ValueReader SqlValue
reader
instance FromSqlField SqlValue where
fieldDecoder :: FieldDecoder SqlValue
fieldDecoder = FieldDecoder SqlValue
sqlValueDecoder
data RowPart a = RowPart (Int -> Prepared (P.Recipe B.ByteString a))
data RowDecoder a = RowDecoder
{ forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
compileRowAt :: TdsContext -> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
, forall a. RowDecoder a -> Int
numExpectedColumns :: !Int
}
instance Functor RowDecoder where
fmap :: forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
fmap = (a -> b) -> RowDecoder a -> RowDecoder b
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRowCalled
{-# INLINE fmap #-}
instance Applicative RowDecoder where
pure :: forall a. a -> RowDecoder a
pure a
a = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder (\TdsContext
_ ResultSetInfo
_ Int
_ -> RowPart a -> Either DecodeError (RowPart a)
forall a b. b -> Either a b
Right ((Int -> Prepared (Recipe ByteString a)) -> RowPart a
forall a. (Int -> Prepared (Recipe ByteString a)) -> RowPart a
RowPart (\Int
_ -> Recipe ByteString a -> Prepared (Recipe ByteString a)
forall a. a -> Prepared a
Prepared (a -> Recipe ByteString a
forall a. a -> Recipe ByteString a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a)))) Int
0
<*> :: forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
(<*>) = RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
apRowCalled
{-# INLINE (<*>) #-}
liftA2 :: forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftA2 = (a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRowCalled
{-# INLINE liftA2 #-}
mapRow :: (a -> b) -> RowDecoder a -> RowDecoder b
mapRow :: forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow a -> b
f (RowDecoder TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
c Int
n) = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart b))
-> Int -> RowDecoder b
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder
(\TdsContext
ctx ResultSetInfo
rs Int
i -> do
RowPart prepare <- TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
c TdsContext
ctx ResultSetInfo
rs Int
i
pure $ RowPart $ \Int
ahead -> case Int -> Prepared (Recipe ByteString a)
prepare Int
ahead of
Prepared Recipe ByteString a
read -> Recipe ByteString b -> Prepared (Recipe ByteString b)
forall a. a -> Prepared a
Prepared ((a -> b) -> Recipe ByteString a -> Recipe ByteString b
forall a b. (a -> b) -> Recipe ByteString a -> Recipe ByteString b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Recipe ByteString a
read)) Int
n
{-# INLINE mapRow #-}
liftRow :: (a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow :: forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow a -> b -> c
f (RowDecoder TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
ca Int
na) (RowDecoder TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart b)
cb Int
nb) = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart c))
-> Int -> RowDecoder c
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder
(\TdsContext
ctx ResultSetInfo
rs Int
i -> do
RowPart prepareA <- TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
ca TdsContext
ctx ResultSetInfo
rs Int
i
RowPart prepareB <- cb ctx rs $! i + na
pure $ RowPart $ \Int
ahead -> case (Int -> Prepared (Recipe ByteString a)
prepareA Int
ahead, Int -> Prepared (Recipe ByteString b)
prepareB Int
ahead) of
(Prepared Recipe ByteString a
readA, Prepared Recipe ByteString b
readB) -> Recipe ByteString c -> Prepared (Recipe ByteString c)
forall a. a -> Prepared a
Prepared ((a -> b -> c)
-> Recipe ByteString a
-> Recipe ByteString b
-> Recipe ByteString c
forall a b c.
(a -> b -> c)
-> Recipe ByteString a
-> Recipe ByteString b
-> Recipe ByteString c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> c
f Recipe ByteString a
readA (Recipe ByteString b -> Recipe ByteString b
forall env a. Recipe env a -> Recipe env a
P.dynamic Recipe ByteString b
readB))) (Int
na Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
nb)
{-# INLINE liftRow #-}
apRow :: RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
apRow :: forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
apRow = ((a -> b) -> a -> b)
-> RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow (a -> b) -> a -> b
forall a. a -> a
id
{-# INLINE apRow #-}
mapRowCalled :: (a -> b) -> RowDecoder a -> RowDecoder b
mapRowCalled :: forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRowCalled = (a -> b) -> RowDecoder a -> RowDecoder b
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow
{-# OPAQUE mapRowCalled #-}
liftRowCalled :: (a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRowCalled :: forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRowCalled = (a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow
{-# OPAQUE liftRowCalled #-}
apRowCalled :: RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
apRowCalled :: forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
apRowCalled = RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
apRow
{-# OPAQUE apRowCalled #-}
consRowCalled :: RowDecoder a -> RowDecoder [a] -> RowDecoder [a]
consRowCalled :: forall a. RowDecoder a -> RowDecoder [a] -> RowDecoder [a]
consRowCalled = (a -> [a] -> [a])
-> RowDecoder a -> RowDecoder [a] -> RowDecoder [a]
forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow (:)
{-# OPAQUE consRowCalled #-}
lift3RowCalled :: (a -> b -> c -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder r
lift3RowCalled :: forall a b c r.
(a -> b -> c -> r)
-> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder r
lift3RowCalled a -> b -> c -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 = (a -> b -> c -> r) -> RowDecoder a -> RowDecoder (b -> c -> r)
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow (\a
x1 b
x2 c
x3 -> a -> b -> c -> r
f a
x1 b
x2 c
x3) RowDecoder a
d1 RowDecoder (b -> c -> r) -> RowDecoder b -> RowDecoder (c -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder b
d2 RowDecoder (c -> r) -> RowDecoder c -> RowDecoder r
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder c
d3
{-# OPAQUE lift3RowCalled #-}
lift4RowCalled :: (a -> b -> c -> d -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder r
lift4RowCalled :: forall a b c d r.
(a -> b -> c -> d -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder r
lift4RowCalled a -> b -> c -> d -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 = (a -> b -> c -> d -> r)
-> RowDecoder a -> RowDecoder (b -> c -> d -> r)
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow (\a
x1 b
x2 c
x3 d
x4 -> a -> b -> c -> d -> r
f a
x1 b
x2 c
x3 d
x4) RowDecoder a
d1 RowDecoder (b -> c -> d -> r)
-> RowDecoder b -> RowDecoder (c -> d -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder b
d2 RowDecoder (c -> d -> r) -> RowDecoder c -> RowDecoder (d -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder c
d3 RowDecoder (d -> r) -> RowDecoder d -> RowDecoder r
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder d
d4
{-# OPAQUE lift4RowCalled #-}
lift5RowCalled :: (a -> b -> c -> d -> e -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder r
lift5RowCalled :: forall a b c d e r.
(a -> b -> c -> d -> e -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder r
lift5RowCalled a -> b -> c -> d -> e -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 = (a -> b -> c -> d -> e -> r)
-> RowDecoder a -> RowDecoder (b -> c -> d -> e -> r)
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow (\a
x1 b
x2 c
x3 d
x4 e
x5 -> a -> b -> c -> d -> e -> r
f a
x1 b
x2 c
x3 d
x4 e
x5) RowDecoder a
d1 RowDecoder (b -> c -> d -> e -> r)
-> RowDecoder b -> RowDecoder (c -> d -> e -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder b
d2 RowDecoder (c -> d -> e -> r)
-> RowDecoder c -> RowDecoder (d -> e -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder c
d3 RowDecoder (d -> e -> r) -> RowDecoder d -> RowDecoder (e -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder d
d4 RowDecoder (e -> r) -> RowDecoder e -> RowDecoder r
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder e
d5
{-# OPAQUE lift5RowCalled #-}
lift6RowCalled :: (a -> b -> c -> d -> e -> g -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder r
lift6RowCalled :: forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled a -> b -> c -> d -> e -> g -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 = (a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a -> RowDecoder (b -> c -> d -> e -> g -> r)
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow (\a
x1 b
x2 c
x3 d
x4 e
x5 g
x6 -> a -> b -> c -> d -> e -> g -> r
f a
x1 b
x2 c
x3 d
x4 e
x5 g
x6) RowDecoder a
d1 RowDecoder (b -> c -> d -> e -> g -> r)
-> RowDecoder b -> RowDecoder (c -> d -> e -> g -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder b
d2 RowDecoder (c -> d -> e -> g -> r)
-> RowDecoder c -> RowDecoder (d -> e -> g -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder c
d3 RowDecoder (d -> e -> g -> r)
-> RowDecoder d -> RowDecoder (e -> g -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder d
d4 RowDecoder (e -> g -> r) -> RowDecoder e -> RowDecoder (g -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder e
d5 RowDecoder (g -> r) -> RowDecoder g -> RowDecoder r
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder g
d6
{-# OPAQUE lift6RowCalled #-}
lift7RowCalled :: (a -> b -> c -> d -> e -> g -> h -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder h -> RowDecoder r
lift7RowCalled :: forall a b c d e g h r.
(a -> b -> c -> d -> e -> g -> h -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder r
lift7RowCalled a -> b -> c -> d -> e -> g -> h -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 = ((e -> g -> h -> r) -> e -> g -> h -> r)
-> RowDecoder (e -> g -> h -> r)
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder r
forall a b c d r.
(a -> b -> c -> d -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder r
lift4RowCalled (e -> g -> h -> r) -> e -> g -> h -> r
forall a. a -> a
id ((a -> b -> c -> d -> e -> g -> h -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder (e -> g -> h -> r)
forall a b c d r.
(a -> b -> c -> d -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder r
lift4RowCalled a -> b -> c -> d -> e -> g -> h -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4) RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7
{-# OPAQUE lift7RowCalled #-}
lift8RowCalled :: (a -> b -> c -> d -> e -> g -> h -> i -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder r
lift8RowCalled :: forall a b c d e g h i r.
(a -> b -> c -> d -> e -> g -> h -> i -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder r
lift8RowCalled a -> b -> c -> d -> e -> g -> h -> i -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 = ((d -> e -> g -> h -> i -> r) -> d -> e -> g -> h -> i -> r)
-> RowDecoder (d -> e -> g -> h -> i -> r)
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder r
forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled (d -> e -> g -> h -> i -> r) -> d -> e -> g -> h -> i -> r
forall a. a -> a
id ((a -> b -> c -> d -> e -> g -> h -> i -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder (d -> e -> g -> h -> i -> r)
forall a b c r.
(a -> b -> c -> r)
-> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder r
lift3RowCalled a -> b -> c -> d -> e -> g -> h -> i -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3) RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8
{-# OPAQUE lift8RowCalled #-}
lift9RowCalled :: (a -> b -> c -> d -> e -> g -> h -> i -> j -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder r
lift9RowCalled :: forall a b c d e g h i j r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder r
lift9RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9 = ((e -> g -> h -> i -> j -> r) -> e -> g -> h -> i -> j -> r)
-> RowDecoder (e -> g -> h -> i -> j -> r)
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder r
forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled (e -> g -> h -> i -> j -> r) -> e -> g -> h -> i -> j -> r
forall a. a -> a
id ((a -> b -> c -> d -> e -> g -> h -> i -> j -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder (e -> g -> h -> i -> j -> r)
forall a b c d r.
(a -> b -> c -> d -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder r
lift4RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4) RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9
{-# OPAQUE lift9RowCalled #-}
lift10RowCalled :: (a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder k -> RowDecoder r
lift10RowCalled :: forall a b c d e g h i j k r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder r
lift10RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9 RowDecoder k
d10 = ((g -> h -> i -> j -> k -> r) -> g -> h -> i -> j -> k -> r)
-> RowDecoder (g -> h -> i -> j -> k -> r)
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder r
forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled (g -> h -> i -> j -> k -> r) -> g -> h -> i -> j -> k -> r
forall a. a -> a
id ((a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder (g -> h -> i -> j -> k -> r)
forall a b c d e r.
(a -> b -> c -> d -> e -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder r
lift5RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5) RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9 RowDecoder k
d10
{-# OPAQUE lift10RowCalled #-}
lift11RowCalled :: (a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder k -> RowDecoder l -> RowDecoder r
lift11RowCalled :: forall a b c d e g h i j k l r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder r
lift11RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9 RowDecoder k
d10 RowDecoder l
d11 = ((h -> i -> j -> k -> l -> r) -> h -> i -> j -> k -> l -> r)
-> RowDecoder (h -> i -> j -> k -> l -> r)
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder r
forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled (h -> i -> j -> k -> l -> r) -> h -> i -> j -> k -> l -> r
forall a. a -> a
id ((a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder (h -> i -> j -> k -> l -> r)
forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6) RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9 RowDecoder k
d10 RowDecoder l
d11
{-# OPAQUE lift11RowCalled #-}
lift12RowCalled :: (a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r) -> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder k -> RowDecoder l -> RowDecoder m -> RowDecoder r
lift12RowCalled :: forall a b c d e g h i j k l m r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder m
-> RowDecoder r
lift12RowCalled a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r
f RowDecoder a
d1 RowDecoder b
d2 RowDecoder c
d3 RowDecoder d
d4 RowDecoder e
d5 RowDecoder g
d6 RowDecoder h
d7 RowDecoder i
d8 RowDecoder j
d9 RowDecoder k
d10 RowDecoder l
d11 RowDecoder m
d12 = (a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder a
-> RowDecoder
(b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow (\a
x1 b
x2 c
x3 d
x4 e
x5 g
x6 h
x7 i
x8 j
x9 k
x10 l
x11 m
x12 -> a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r
f a
x1 b
x2 c
x3 d
x4 e
x5 g
x6 h
x7 i
x8 j
x9 k
x10 l
x11 m
x12) RowDecoder a
d1 RowDecoder
(b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder b
-> RowDecoder (c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder b
d2 RowDecoder (c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder c
-> RowDecoder (d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder c
d3 RowDecoder (d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder d
-> RowDecoder (e -> g -> h -> i -> j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder d
d4 RowDecoder (e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder e
-> RowDecoder (g -> h -> i -> j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder e
d5 RowDecoder (g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder g -> RowDecoder (h -> i -> j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder g
d6 RowDecoder (h -> i -> j -> k -> l -> m -> r)
-> RowDecoder h -> RowDecoder (i -> j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder h
d7 RowDecoder (i -> j -> k -> l -> m -> r)
-> RowDecoder i -> RowDecoder (j -> k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder i
d8 RowDecoder (j -> k -> l -> m -> r)
-> RowDecoder j -> RowDecoder (k -> l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder j
d9 RowDecoder (k -> l -> m -> r)
-> RowDecoder k -> RowDecoder (l -> m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder k
d10 RowDecoder (l -> m -> r) -> RowDecoder l -> RowDecoder (m -> r)
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder l
d11 RowDecoder (m -> r) -> RowDecoder m -> RowDecoder r
forall a b. RowDecoder (a -> b) -> RowDecoder a -> RowDecoder b
`apRow` RowDecoder m
d12
{-# OPAQUE lift12RowCalled #-}
{-# RULES
"RowDecoder/fmap-ap" forall f d1 d2. apRowCalled (mapRowCalled f d1) d2 = liftRowCalled f d1 d2
"RowDecoder/lift2-ap" forall f d1 d2 d3. apRowCalled (liftRowCalled f d1 d2) d3 = lift3RowCalled f d1 d2 d3
"RowDecoder/lift3-ap" forall f d1 d2 d3 d4. apRowCalled (lift3RowCalled f d1 d2 d3) d4 = lift4RowCalled f d1 d2 d3 d4
"RowDecoder/lift4-ap" forall f d1 d2 d3 d4 d5. apRowCalled (lift4RowCalled f d1 d2 d3 d4) d5 = lift5RowCalled f d1 d2 d3 d4 d5
"RowDecoder/lift5-ap" forall f d1 d2 d3 d4 d5 d6. apRowCalled (lift5RowCalled f d1 d2 d3 d4 d5) d6 = lift6RowCalled f d1 d2 d3 d4 d5 d6
"RowDecoder/lift6-ap" forall f d1 d2 d3 d4 d5 d6 d7. apRowCalled (lift6RowCalled f d1 d2 d3 d4 d5 d6) d7 = lift7RowCalled f d1 d2 d3 d4 d5 d6 d7
"RowDecoder/lift7-ap" forall f d1 d2 d3 d4 d5 d6 d7 d8. apRowCalled (lift7RowCalled f d1 d2 d3 d4 d5 d6 d7) d8 = lift8RowCalled f d1 d2 d3 d4 d5 d6 d7 d8
"RowDecoder/lift8-ap" forall f d1 d2 d3 d4 d5 d6 d7 d8 d9. apRowCalled (lift8RowCalled f d1 d2 d3 d4 d5 d6 d7 d8) d9 = lift9RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9
"RowDecoder/lift9-ap" forall f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10. apRowCalled (lift9RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9) d10 = lift10RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10
"RowDecoder/lift10-ap" forall f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11. apRowCalled (lift10RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10) d11 = lift11RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11
"RowDecoder/lift11-ap" forall f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12. apRowCalled (lift11RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11) d12 = lift12RowCalled f d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12
"RowDecoder/cons" forall d ds. liftRowCalled (:) d ds = consRowCalled d ds
#-}
singleField :: FieldDecoder a -> RowDecoder a
singleField :: forall a. FieldDecoder a -> RowDecoder a
singleField FieldDecoder a
decoder = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder
(\TdsContext
ctx ResultSetInfo
rs Int
i -> case ResultSetInfo -> Int -> Either DecodeError ColumnInfo
columnAt ResultSetInfo
rs Int
i of
Left DecodeError
err -> DecodeError -> Either DecodeError (RowPart a)
forall a b. a -> Either a b
Left DecodeError
err
Right ColumnInfo
col -> case FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
forall a.
FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compileField FieldDecoder a
decoder TdsContext
ctx ColumnInfo
col of
Left [Char]
err -> DecodeError -> Either DecodeError (RowPart a)
forall a b. a -> Either a b
Left (Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col)) [Char]
err)
Right CellDecoder a
d -> RowPart a -> Either DecodeError (RowPart a)
forall a b. b -> Either a b
Right (ResultSetInfo -> Int -> ColumnInfo -> CellDecoder a -> RowPart a
forall a.
ResultSetInfo -> Int -> ColumnInfo -> CellDecoder a -> RowPart a
cellPart ResultSetInfo
rs Int
i ColumnInfo
col CellDecoder a
d)) Int
1
{-# OPAQUE singleField #-}
inlinedField :: FieldDecoder a -> RowDecoder a
inlinedField :: forall a. FieldDecoder a -> RowDecoder a
inlinedField FieldDecoder a
d = FieldDecoder a -> FieldDecoder a -> Nulls a a -> RowDecoder a
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder a
d FieldDecoder a
d Nulls a a
forall a. Nulls a a
NoNulls
{-# INLINE inlinedField #-}
inlinedNullableField :: FieldDecoder a -> RowDecoder (Maybe a)
inlinedNullableField :: forall a. FieldDecoder a -> RowDecoder (Maybe a)
inlinedNullableField FieldDecoder a
d = FieldDecoder a
-> FieldDecoder a -> Nulls a (Maybe a) -> RowDecoder (Maybe a)
forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder a
d FieldDecoder a
d Nulls a (Maybe a)
forall a. Nulls a (Maybe a)
Nulls
{-# INLINE inlinedNullableField #-}
byColumn :: (ColumnInfo -> RowDecoder a) -> RowDecoder a
byColumn :: forall a. (ColumnInfo -> RowDecoder a) -> RowDecoder a
byColumn ColumnInfo -> RowDecoder a
choose = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder
(\TdsContext
ctx ResultSetInfo
rs Int
i -> case ResultSetInfo -> Int -> Either DecodeError ColumnInfo
columnAt ResultSetInfo
rs Int
i of
Left DecodeError
err -> DecodeError -> Either DecodeError (RowPart a)
forall a b. a -> Either a b
Left DecodeError
err
Right ColumnInfo
col -> case ColumnInfo -> RowDecoder a
choose ColumnInfo
col of
RowDecoder TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
compile Int
1 -> TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
compile TdsContext
ctx ResultSetInfo
rs Int
i
RowDecoder TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a)
_ Int
n -> DecodeError -> Either DecodeError (RowPart a)
forall a b. a -> Either a b
Left (Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col))
([Char]
"byColumn chose a decoder of " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" columns, not 1"))) Int
1
{-# OPAQUE byColumn #-}
columnAt :: ResultSetInfo -> Int -> Either DecodeError ColumnInfo
columnAt :: ResultSetInfo -> Int -> Either DecodeError ColumnInfo
columnAt ResultSetInfo
rs Int
i
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> Bool -> Bool
|| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs =
DecodeError -> Either DecodeError ColumnInfo
forall a b. a -> Either a b
Left (Maybe Text -> [Char] -> DecodeError
DecodeError Maybe Text
forall a. Maybe a
Nothing ([Char]
"expected 1 column, got " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i))))
| Bool
otherwise = ColumnInfo -> Either DecodeError ColumnInfo
forall a b. b -> Either a b
Right (SmallArray ColumnInfo -> Int -> ColumnInfo
forall a. SmallArray a -> Int -> a
indexSmallArray (ResultSetInfo -> SmallArray ColumnInfo
rsColumnArray ResultSetInfo
rs) Int
i)
{-# NOINLINE columnAt #-}
cellPart :: ResultSetInfo -> Int -> ColumnInfo -> CellDecoder a -> RowPart a
cellPart :: forall a.
ResultSetInfo -> Int -> ColumnInfo -> CellDecoder a -> RowPart a
cellPart ResultSetInfo
rs Int
i ColumnInfo
col CellDecoder a
d = (Int -> Prepared (Recipe ByteString a)) -> RowPart a
forall a. (Int -> Prepared (Recipe ByteString a)) -> RowPart a
RowPart ((Int -> Prepared (Recipe ByteString a)) -> RowPart a)
-> (Int -> Prepared (Recipe ByteString a)) -> RowPart a
forall a b. (a -> b) -> a -> b
$ \Int
ahead ->
let shape :: ColumnShape
shape = TypeInfo -> ColumnShape
rowShape (ColumnInfo -> TypeInfo
columnType ColumnInfo
col)
present :: Recipe ByteString a
present = Parser a -> Recipe ByteString a
forall a env. Parser a -> Recipe env a
P.liftParser (ColumnShape -> Parser Cell
cellHead ColumnShape
shape Parser Cell -> (Cell -> Parser a) -> Parser a
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
forall a. ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
readCellRecipe ColumnInfo
col CellDecoder a
d Int
ahead)
absent :: Recipe ByteString a
absent = Parser a -> Recipe ByteString a
forall a env. Parser a -> Recipe env a
P.liftParser (ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
forall a. ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
readCellRecipe ColumnInfo
col CellDecoder a
d Int
ahead Cell
NullCell)
in Recipe ByteString a -> Prepared (Recipe ByteString a)
forall a. a -> Prepared a
Prepared (Recipe ByteString a -> Prepared (Recipe ByteString a))
-> Recipe ByteString a -> Prepared (Recipe ByteString a)
forall a b. (a -> b) -> a -> b
$ Recipe ByteString a
-> (ReadFailure -> Recipe ByteString a) -> Recipe ByteString a
forall env a.
Recipe env a -> (ReadFailure -> Recipe env a) -> Recipe env a
P.recover (Recipe ByteString ByteString
forall env. Recipe env env
P.ask Recipe ByteString ByteString
-> (ByteString -> Recipe ByteString a) -> Recipe ByteString a
forall a b.
Recipe ByteString a
-> (a -> Recipe ByteString b) -> Recipe ByteString b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ByteString
bitmap -> if ByteString -> Int -> Bool
columnNull ByteString
bitmap Int
i then Recipe ByteString a
absent else Recipe ByteString a
present) (ResultSetInfo -> Int -> ReadFailure -> Recipe ByteString a
forall a.
ResultSetInfo -> Int -> ReadFailure -> Recipe ByteString a
skipLater ResultSetInfo
rs Int
i)
{-# NOINLINE cellPart #-}
skipLater :: ResultSetInfo -> Int -> ReadFailure -> P.Recipe B.ByteString a
skipLater :: forall a.
ResultSetInfo -> Int -> ReadFailure -> Recipe ByteString a
skipLater ResultSetInfo
rs Int
i = \ReadFailure
failure -> do
bitmap <- Recipe ByteString ByteString
forall env. Recipe env env
P.ask
P.liftParser (skipCells bitmap later)
P.failValue failure
where later :: [(Int, ColumnShape)]
later = Int -> [(Int, ColumnShape)] -> [(Int, ColumnShape)]
forall a. Int -> [a] -> [a]
drop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (ResultSetInfo -> [(Int, ColumnShape)]
rsCells ResultSetInfo
rs)
{-# NOINLINE skipLater #-}
otherCell :: ColumnInfo -> CellDecoder a -> Int -> ColumnShape -> Prepared (Parser a)
otherCell :: forall a.
ColumnInfo
-> CellDecoder a -> Int -> ColumnShape -> Prepared (Parser a)
otherCell ColumnInfo
col CellDecoder a
d Int
ahead ColumnShape
shape = Parser a -> Prepared (Parser a)
forall a. a -> Prepared a
Prepared (ColumnShape -> Parser Cell
cellHead ColumnShape
shape Parser Cell -> (Cell -> Parser a) -> Parser a
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
forall a. ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
readCellRecipe ColumnInfo
col CellDecoder a
d Int
ahead)
{-# NOINLINE otherCell #-}
sharedCell :: Nulls a b -> FieldDecoder a -> TdsContext -> ColumnInfo -> Int -> ColumnShape -> Prepared (Parser b)
sharedCell :: forall a b.
Nulls a b
-> FieldDecoder a
-> TdsContext
-> ColumnInfo
-> Int
-> ColumnShape
-> Prepared (Parser b)
sharedCell Nulls a b
nulls FieldDecoder a
shared TdsContext
ctx ColumnInfo
col Int
ahead ColumnShape
shape = case FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
forall a.
FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compileField FieldDecoder a
shared TdsContext
ctx ColumnInfo
col of
Right CellDecoder a
d -> ColumnInfo
-> CellDecoder b -> Int -> ColumnShape -> Prepared (Parser b)
forall a.
ColumnInfo
-> CellDecoder a -> Int -> ColumnShape -> Prepared (Parser a)
otherCell ColumnInfo
col (Nulls a b -> CellDecoder a -> CellDecoder b
forall a b. Nulls a b -> CellDecoder a -> CellDecoder b
nullsCell Nulls a b
nulls CellDecoder a
d) Int
ahead ColumnShape
shape
Left [Char]
err -> Parser b -> Prepared (Parser b)
forall a. a -> Prepared a
Prepared (ReadFailure -> Parser b
forall env a. ReadFailure -> Recipe env a
P.failValue (DecodeError -> ReadFailure
DecodeFailed (Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col)) [Char]
err)))
{-# NOINLINE sharedCell #-}
cellRowDecoder :: forall a b. FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder :: forall a b.
FieldDecoder a -> FieldDecoder a -> Nulls a b -> RowDecoder b
cellRowDecoder FieldDecoder a
shared FieldDecoder a
inlined = \Nulls a b
nulls -> (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart b))
-> Int -> RowDecoder b
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder
(\TdsContext
ctx ResultSetInfo
rs Int
i -> case ResultSetInfo -> Int -> Either DecodeError ColumnInfo
columnAt ResultSetInfo
rs Int
i of
Left DecodeError
err -> DecodeError -> Either DecodeError (RowPart b)
forall a b. a -> Either a b
Left DecodeError
err
Right ColumnInfo
col -> case FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
forall a.
FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compileField FieldDecoder a
inlined TdsContext
ctx ColumnInfo
col of
Left [Char]
err -> DecodeError -> Either DecodeError (RowPart b)
forall a b. a -> Either a b
Left (Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col)) [Char]
err)
Right d :: CellDecoder a
d@FoldingCell{} -> RowPart b -> Either DecodeError (RowPart b)
forall a b. b -> Either a b
Right (ResultSetInfo -> Int -> ColumnInfo -> CellDecoder b -> RowPart b
forall a.
ResultSetInfo -> Int -> ColumnInfo -> CellDecoder a -> RowPart a
cellPart ResultSetInfo
rs Int
i ColumnInfo
col (Nulls a b -> CellDecoder a -> CellDecoder b
forall a b. Nulls a b -> CellDecoder a -> CellDecoder b
nullsCell Nulls a b
nulls CellDecoder a
d))
Right (CellDecoder Either [Char] a
onNull ValueReader a
borrowed ValueReader a
_) ->
let shape :: ColumnShape
shape = TypeInfo -> ColumnShape
rowShape (ColumnInfo -> TypeInfo
columnType ColumnInfo
col)
!width :: Int
width = case ColumnShape
shape of
ConstantCell (Sized Int
_) -> Int
0
ColumnShape
ByteLength -> Int
1
ColumnShape
ShortLength -> Int
2
ColumnShape
_ -> -Int
1 :: Int
!marker :: Int
marker = case ColumnShape
shape of
ConstantCell (Sized Int
n) -> Int
n
ColumnShape
ShortLength -> Int
0xFFFF
ColumnShape
_ -> Int
0
named :: [Char] -> ReadFailure
named = DecodeError -> ReadFailure
DecodeFailed (DecodeError -> ReadFailure)
-> ([Char] -> DecodeError) -> [Char] -> ReadFailure
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col))
convert :: ByteString -> Either ReadFailure b
convert ByteString
bytes = case ValueReader a
borrowed ByteString
bytes of
Left [Char]
e -> ReadFailure -> Either ReadFailure b
forall a b. a -> Either a b
Left ([Char] -> ReadFailure
named [Char]
e)
Right a
v -> b -> Either ReadFailure b
forall a b. b -> Either a b
Right (case Nulls a b
nulls of
Nulls a b
NoNulls -> a
b
v
Nulls a b
Nulls -> a -> Maybe a
forall a. a -> Maybe a
Just a
v)
nullValue :: P.Recipe env b
nullValue :: forall env. Recipe env b
nullValue = case Nulls a b
nulls of
Nulls a b
NoNulls -> ([Char] -> Recipe env b)
-> (b -> Recipe env b) -> Either [Char] b -> Recipe env b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ReadFailure -> Recipe env b
forall env a. ReadFailure -> Recipe env a
P.failValue (ReadFailure -> Recipe env b)
-> ([Char] -> ReadFailure) -> [Char] -> Recipe env b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ReadFailure
named) b -> Recipe env b
forall a. a -> Recipe env a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Either [Char] a
Either [Char] b
onNull
Nulls a b
Nulls -> b -> Recipe env b
forall a. a -> Recipe env a
forall (f :: * -> *) a. Applicative f => a -> f a
pure b
Maybe a
forall a. Maybe a
Nothing
in RowPart b -> Either DecodeError (RowPart b)
forall a b. b -> Either a b
Right (RowPart b -> Either DecodeError (RowPart b))
-> RowPart b -> Either DecodeError (RowPart b)
forall a b. (a -> b) -> a -> b
$ (Int -> Prepared (Recipe ByteString b)) -> RowPart b
forall a. (Int -> Prepared (Recipe ByteString a)) -> RowPart a
RowPart ((Int -> Prepared (Recipe ByteString b)) -> RowPart b)
-> (Int -> Prepared (Recipe ByteString b)) -> RowPart b
forall a b. (a -> b) -> a -> b
$ \Int
ahead ->
let other :: Parser b
other = case Nulls a b
-> FieldDecoder a
-> TdsContext
-> ColumnInfo
-> Int
-> ColumnShape
-> Prepared (Parser b)
forall a b.
Nulls a b
-> FieldDecoder a
-> TdsContext
-> ColumnInfo
-> Int
-> ColumnShape
-> Prepared (Parser b)
sharedCell Nulls a b
nulls FieldDecoder a
shared TdsContext
ctx ColumnInfo
col Int
ahead ColumnShape
shape of Prepared Parser b
recipe -> Parser b
recipe
present :: Recipe ByteString b
present = Int
-> Int
-> Int
-> (ByteString -> Either ReadFailure b)
-> Recipe ByteString b
-> Recipe ByteString b
-> Recipe ByteString b
forall a.
Int
-> Int
-> Int
-> (ByteString -> Either ReadFailure a)
-> Recipe ByteString a
-> Recipe ByteString a
-> Recipe ByteString a
P.prefixedRowValue Int
i Int
width Int
marker ByteString -> Either ReadFailure b
convert Recipe ByteString b
forall env. Recipe env b
nullValue (Parser b -> Recipe ByteString b
forall a env. Parser a -> Recipe env a
P.liftParser Parser b
other)
in Recipe ByteString b -> Prepared (Recipe ByteString b)
forall a. a -> Prepared a
Prepared (Recipe ByteString b -> Prepared (Recipe ByteString b))
-> Recipe ByteString b -> Prepared (Recipe ByteString b)
forall a b. (a -> b) -> a -> b
$ Recipe ByteString b
-> (ReadFailure -> Recipe ByteString b) -> Recipe ByteString b
forall env a.
Recipe env a -> (ReadFailure -> Recipe env a) -> Recipe env a
P.recover
Recipe ByteString b
present
(ResultSetInfo -> Int -> ReadFailure -> Recipe ByteString b
forall a.
ResultSetInfo -> Int -> ReadFailure -> Recipe ByteString a
skipLater ResultSetInfo
rs Int
i)
Right CellDecoder a
d -> RowPart b -> Either DecodeError (RowPart b)
forall a b. b -> Either a b
Right (ResultSetInfo -> Int -> ColumnInfo -> CellDecoder b -> RowPart b
forall a.
ResultSetInfo -> Int -> ColumnInfo -> CellDecoder a -> RowPart a
cellPart ResultSetInfo
rs Int
i ColumnInfo
col (Nulls a b -> CellDecoder a -> CellDecoder b
forall a b. Nulls a b -> CellDecoder a -> CellDecoder b
nullsCell Nulls a b
nulls CellDecoder a
d))) Int
1
{-# INLINE cellRowDecoder #-}
class FromSqlRow a where
rowDecoder :: RowDecoder a
default rowDecoder :: (Generic a, GRowDecoder (Rep a)) => RowDecoder a
rowDecoder = RowDecoder a
forall a. (Generic a, GRowDecoder (Rep a)) => RowDecoder a
genericFromSqlRow
compileRowDecoder :: RowDecoder a -> TdsContext -> [ColumnInfo] -> Either DecodeError (CompiledRow a)
compileRowDecoder :: forall a.
RowDecoder a
-> TdsContext -> [ColumnInfo] -> Either DecodeError (CompiledRow a)
compileRowDecoder RowDecoder a
dec TdsContext
ctx [ColumnInfo]
cols = RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Either DecodeError (CompiledRow a)
forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Either DecodeError (CompiledRow a)
compileRowDecoderFor RowDecoder a
dec TdsContext
ctx ([ColumnInfo] -> ResultSetInfo
compileResultSet [ColumnInfo]
cols)
compileRowDecoderFor :: RowDecoder a -> TdsContext -> ResultSetInfo -> Either DecodeError (CompiledRow a)
compileRowDecoderFor :: forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Either DecodeError (CompiledRow a)
compileRowDecoderFor RowDecoder a
dec TdsContext
ctx ResultSetInfo
rs
| ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= RowDecoder a -> Int
forall a. RowDecoder a -> Int
numExpectedColumns RowDecoder a
dec = DecodeError -> Either DecodeError (CompiledRow a)
forall a b. a -> Either a b
Left (DecodeError -> Either DecodeError (CompiledRow a))
-> DecodeError -> Either DecodeError (CompiledRow a)
forall a b. (a -> b) -> a -> b
$ Maybe Text -> [Char] -> DecodeError
DecodeError Maybe Text
forall a. Maybe a
Nothing ([Char] -> DecodeError) -> [Char] -> DecodeError
forall a b. (a -> b) -> a -> b
$
[Char]
"result has " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" column(s) but the row type expects " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (RowDecoder a -> Int
forall a. RowDecoder a -> Int
numExpectedColumns RowDecoder a
dec)
| Bool
otherwise = do
RowPart prepare <- RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
compileRowAt RowDecoder a
dec TdsContext
ctx ResultSetInfo
rs Int
0
pure $ CompiledRow $ \Int
ahead -> case Int -> Prepared (Recipe ByteString a)
prepare Int
ahead of
Prepared Recipe ByteString a
read -> Parser a -> Prepared (Parser a)
forall a. a -> Prepared a
Prepared (Parser a -> Prepared (Parser a))
-> Parser a -> Prepared (Parser a)
forall a b. (a -> b) -> a -> b
$ do
bitmap <- Int -> Parser ByteString
rowBitmap (ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs)
P.withEnv bitmap (P.dynamic read)
sqlRowDecoderFor :: [ColumnInfo] -> RowDecoder SqlRow
sqlRowDecoderFor :: [ColumnInfo] -> RowDecoder SqlRow
sqlRowDecoderFor [ColumnInfo]
cols = (TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart SqlRow))
-> Int -> RowDecoder SqlRow
forall a.
(TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart a))
-> Int -> RowDecoder a
RowDecoder TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart SqlRow)
compile Int
n
where
n :: Int
n = [ColumnInfo] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ColumnInfo]
cols
compile :: TdsContext
-> ResultSetInfo -> Int -> Either DecodeError (RowPart SqlRow)
compile TdsContext
ctx ResultSetInfo
rs Int
i = do
parts <- (Int -> Either DecodeError (RowPart SqlValue))
-> [Int] -> Either DecodeError [RowPart SqlValue]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (RowDecoder SqlValue
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart SqlValue)
forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
compileRowAt (FieldDecoder SqlValue -> RowDecoder SqlValue
forall a. FieldDecoder a -> RowDecoder a
singleField FieldDecoder SqlValue
deferred) TdsContext
ctx ResultSetInfo
rs) (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
n [Int
i ..])
pure $ RowPart $ \Int
ahead ->
let !cells :: [Recipe ByteString SqlValue]
cells = Int -> [RowPart SqlValue] -> [Recipe ByteString SqlValue]
forall {a}. Int -> [RowPart a] -> [Recipe ByteString a]
prepareAll Int
ahead [RowPart SqlValue]
parts
in Recipe ByteString SqlRow -> Prepared (Recipe ByteString SqlRow)
forall a. a -> Prepared a
Prepared ([ColumnInfo] -> [SqlValue] -> SqlRow
SqlRow [ColumnInfo]
cols ([SqlValue] -> SqlRow)
-> Recipe ByteString [SqlValue] -> Recipe ByteString SqlRow
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Recipe ByteString SqlValue] -> Recipe ByteString [SqlValue]
forall {env} {a}. [Recipe env a] -> Recipe env [a]
values [Recipe ByteString SqlValue]
cells)
prepareAll :: Int -> [RowPart a] -> [Recipe ByteString a]
prepareAll Int
_ [] = []
prepareAll Int
ahead (RowPart Int -> Prepared (Recipe ByteString a)
prepare : [RowPart a]
parts) = case Int -> Prepared (Recipe ByteString a)
prepare Int
ahead of
Prepared Recipe ByteString a
read -> let !rest :: [Recipe ByteString a]
rest = Int -> [RowPart a] -> [Recipe ByteString a]
prepareAll Int
ahead [RowPart a]
parts in Recipe ByteString a
read Recipe ByteString a
-> [Recipe ByteString a] -> [Recipe ByteString a]
forall a. a -> [a] -> [a]
: [Recipe ByteString a]
rest
values :: [Recipe env a] -> Recipe env [a]
values [] = [a] -> Recipe env [a]
forall a. a -> Recipe env a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
values (Recipe env a
cell : [Recipe env a]
cells) = (a -> [a] -> [a])
-> Recipe env a -> Recipe env [a] -> Recipe env [a]
forall a b c.
(a -> b -> c) -> Recipe env a -> Recipe env b -> Recipe env c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (:) (Recipe env a -> Recipe env a
forall env a. Recipe env a -> Recipe env a
P.dynamic Recipe env a
cell) ([Recipe env a] -> Recipe env [a]
values [Recipe env a]
cells)
deferred :: FieldDecoder SqlValue
deferred = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder SqlValue))
-> FieldDecoder SqlValue
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder SqlValue))
-> FieldDecoder SqlValue)
-> (TdsContext
-> ColumnInfo -> Either [Char] (CellDecoder SqlValue))
-> FieldDecoder SqlValue
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> case FieldDecoder SqlValue
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder SqlValue)
forall a.
FieldDecoder a
-> TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a)
compileField FieldDecoder SqlValue
sqlValueDecoder TdsContext
ctx ColumnInfo
col of
Left [Char]
err -> CellDecoder SqlValue -> Either [Char] (CellDecoder SqlValue)
forall a b. b -> Either a b
Right (Either [Char] SqlValue
-> ValueReader SqlValue
-> ValueReader SqlValue
-> CellDecoder SqlValue
forall a.
Either [Char] a -> ValueReader a -> ValueReader a -> CellDecoder a
CellDecoder ([Char] -> Either [Char] SqlValue
forall a b. a -> Either a b
Left [Char]
err) (Either [Char] SqlValue -> ValueReader SqlValue
forall a b. a -> b -> a
const ([Char] -> Either [Char] SqlValue
forall a b. a -> Either a b
Left [Char]
err)) (Either [Char] SqlValue -> ValueReader SqlValue
forall a b. a -> b -> a
const ([Char] -> Either [Char] SqlValue
forall a b. a -> Either a b
Left [Char]
err)))
Right CellDecoder SqlValue
result -> CellDecoder SqlValue -> Either [Char] (CellDecoder SqlValue)
forall a b. b -> Either a b
Right CellDecoder SqlValue
result
instance FromSqlField a => FromSqlRow (Only a) where
rowDecoder :: RowDecoder (Only a)
rowDecoder = RowDecoder a -> RowDecoder (Only a)
forall a. RowDecoder a -> RowDecoder (Only a)
onlyDecoder RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b) => FromSqlRow (a, b) where
rowDecoder :: RowDecoder (a, b)
rowDecoder = RowDecoder a -> RowDecoder b -> RowDecoder (a, b)
forall a b. RowDecoder a -> RowDecoder b -> RowDecoder (a, b)
tuple2 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c) => FromSqlRow (a, b, c) where
rowDecoder :: RowDecoder (a, b, c)
rowDecoder = RowDecoder a
-> RowDecoder b -> RowDecoder c -> RowDecoder (a, b, c)
forall a b c.
RowDecoder a
-> RowDecoder b -> RowDecoder c -> RowDecoder (a, b, c)
tuple3 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d) => FromSqlRow (a, b, c, d) where
rowDecoder :: RowDecoder (a, b, c, d)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder (a, b, c, d)
forall a b c d.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder (a, b, c, d)
tuple4 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e) => FromSqlRow (a, b, c, d, e) where
rowDecoder :: RowDecoder (a, b, c, d, e)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder (a, b, c, d, e)
forall a b c d e.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder (a, b, c, d, e)
tuple5 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f) => FromSqlRow (a, b, c, d, e, f) where
rowDecoder :: RowDecoder (a, b, c, d, e, f)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder (a, b, c, d, e, f)
forall a b c d e f.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder (a, b, c, d, e, f)
tuple6 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f, FromSqlField g) => FromSqlRow (a, b, c, d, e, f, g) where
rowDecoder :: RowDecoder (a, b, c, d, e, f, g)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder (a, b, c, d, e, f, g)
forall a b c d e f g.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder (a, b, c, d, e, f, g)
tuple7 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder g
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f, FromSqlField g, FromSqlField h) => FromSqlRow (a, b, c, d, e, f, g, h) where
rowDecoder :: RowDecoder (a, b, c, d, e, f, g, h)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder (a, b, c, d, e, f, g, h)
forall a b c d e f g h.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder (a, b, c, d, e, f, g, h)
tuple8 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder g
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder h
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f, FromSqlField g, FromSqlField h, FromSqlField i) => FromSqlRow (a, b, c, d, e, f, g, h, i) where
rowDecoder :: RowDecoder (a, b, c, d, e, f, g, h, i)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder (a, b, c, d, e, f, g, h, i)
forall a b c d e f g h i.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder (a, b, c, d, e, f, g, h, i)
tuple9 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder g
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder h
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder i
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f, FromSqlField g, FromSqlField h, FromSqlField i, FromSqlField j) => FromSqlRow (a, b, c, d, e, f, g, h, i, j) where
rowDecoder :: RowDecoder (a, b, c, d, e, f, g, h, i, j)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder (a, b, c, d, e, f, g, h, i, j)
forall a b c d e f g h i j.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder (a, b, c, d, e, f, g, h, i, j)
tuple10 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder g
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder h
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder i
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder j
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f, FromSqlField g, FromSqlField h, FromSqlField i, FromSqlField j, FromSqlField k) => FromSqlRow (a, b, c, d, e, f, g, h, i, j, k) where
rowDecoder :: RowDecoder (a, b, c, d, e, f, g, h, i, j, k)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k)
forall a b c d e f g h i j k.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k)
tuple11 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder g
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder h
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder i
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder j
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder k
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
instance (FromSqlField a, FromSqlField b, FromSqlField c, FromSqlField d, FromSqlField e, FromSqlField f, FromSqlField g, FromSqlField h, FromSqlField i, FromSqlField j, FromSqlField k, FromSqlField l) => FromSqlRow (a, b, c, d, e, f, g, h, i, j, k, l) where
rowDecoder :: RowDecoder (a, b, c, d, e, f, g, h, i, j, k, l)
rowDecoder = RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k, l)
forall a b c d e f g h i j k l.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k, l)
tuple12 RowDecoder a
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder b
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder c
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder d
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder e
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder f
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder g
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder h
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder i
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder j
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder k
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder RowDecoder l
forall a. FromSqlField a => RowDecoder a
fieldRowDecoder
onlyDecoder :: RowDecoder a -> RowDecoder (Only a)
onlyDecoder :: forall a. RowDecoder a -> RowDecoder (Only a)
onlyDecoder RowDecoder a
a = (a -> Only a) -> RowDecoder a -> RowDecoder (Only a)
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow a -> Only a
forall a. a -> Only a
Only RowDecoder a
a
{-# OPAQUE onlyDecoder #-}
tuple2 :: RowDecoder a -> RowDecoder b -> RowDecoder (a, b)
tuple2 :: forall a b. RowDecoder a -> RowDecoder b -> RowDecoder (a, b)
tuple2 RowDecoder a
a RowDecoder b
b = (a -> b -> (a, b))
-> RowDecoder a -> RowDecoder b -> RowDecoder (a, b)
forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow (,) RowDecoder a
a RowDecoder b
b
{-# OPAQUE tuple2 #-}
tuple3 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder (a, b, c)
tuple3 :: forall a b c.
RowDecoder a
-> RowDecoder b -> RowDecoder c -> RowDecoder (a, b, c)
tuple3 RowDecoder a
a RowDecoder b
b RowDecoder c
c = (a -> b -> c -> (a, b, c))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder (a, b, c)
forall a b c r.
(a -> b -> c -> r)
-> RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder r
lift3RowCalled (,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c
{-# OPAQUE tuple3 #-}
tuple4 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder (a, b, c, d)
tuple4 :: forall a b c d.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder (a, b, c, d)
tuple4 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d = (a -> b -> c -> d -> (a, b, c, d))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder (a, b, c, d)
forall a b c d r.
(a -> b -> c -> d -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder r
lift4RowCalled (,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d
{-# OPAQUE tuple4 #-}
tuple5 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder (a, b, c, d, e)
tuple5 :: forall a b c d e.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder (a, b, c, d, e)
tuple5 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e = (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder (a, b, c, d, e)
forall a b c d e r.
(a -> b -> c -> d -> e -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder r
lift5RowCalled (,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e
{-# OPAQUE tuple5 #-}
tuple6 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder (a, b, c, d, e, f)
tuple6 :: forall a b c d e f.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder (a, b, c, d, e, f)
tuple6 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f = (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder (a, b, c, d, e, f)
forall a b c d e g r.
(a -> b -> c -> d -> e -> g -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder r
lift6RowCalled (,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f
{-# OPAQUE tuple6 #-}
tuple7 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder g -> RowDecoder (a, b, c, d, e, f, g)
tuple7 :: forall a b c d e f g.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder (a, b, c, d, e, f, g)
tuple7 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g = (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder (a, b, c, d, e, f, g)
forall a b c d e g h r.
(a -> b -> c -> d -> e -> g -> h -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder r
lift7RowCalled (,,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g
{-# OPAQUE tuple7 #-}
tuple8 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder g -> RowDecoder h -> RowDecoder (a, b, c, d, e, f, g, h)
tuple8 :: forall a b c d e f g h.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder (a, b, c, d, e, f, g, h)
tuple8 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h = (a -> b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder (a, b, c, d, e, f, g, h)
forall a b c d e g h i r.
(a -> b -> c -> d -> e -> g -> h -> i -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder r
lift8RowCalled (,,,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h
{-# OPAQUE tuple8 #-}
tuple9 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder (a, b, c, d, e, f, g, h, i)
tuple9 :: forall a b c d e f g h i.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder (a, b, c, d, e, f, g, h, i)
tuple9 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i = (a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> (a, b, c, d, e, f, g, h, i))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder (a, b, c, d, e, f, g, h, i)
forall a b c d e g h i j r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder r
lift9RowCalled (,,,,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i
{-# OPAQUE tuple9 #-}
tuple10 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder (a, b, c, d, e, f, g, h, i, j)
tuple10 :: forall a b c d e f g h i j.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder (a, b, c, d, e, f, g, h, i, j)
tuple10 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i RowDecoder j
j = (a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> j
-> (a, b, c, d, e, f, g, h, i, j))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder (a, b, c, d, e, f, g, h, i, j)
forall a b c d e g h i j k r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder r
lift10RowCalled (,,,,,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i RowDecoder j
j
{-# OPAQUE tuple10 #-}
tuple11 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder k -> RowDecoder (a, b, c, d, e, f, g, h, i, j, k)
tuple11 :: forall a b c d e f g h i j k.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k)
tuple11 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i RowDecoder j
j RowDecoder k
k = (a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> j
-> k
-> (a, b, c, d, e, f, g, h, i, j, k))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k)
forall a b c d e g h i j k l r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder r
lift11RowCalled (,,,,,,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i RowDecoder j
j RowDecoder k
k
{-# OPAQUE tuple11 #-}
tuple12 :: RowDecoder a -> RowDecoder b -> RowDecoder c -> RowDecoder d -> RowDecoder e -> RowDecoder f -> RowDecoder g -> RowDecoder h -> RowDecoder i -> RowDecoder j -> RowDecoder k -> RowDecoder l -> RowDecoder (a, b, c, d, e, f, g, h, i, j, k, l)
tuple12 :: forall a b c d e f g h i j k l.
RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k, l)
tuple12 RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i RowDecoder j
j RowDecoder k
k RowDecoder l
l = (a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> j
-> k
-> l
-> (a, b, c, d, e, f, g, h, i, j, k, l))
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder f
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder (a, b, c, d, e, f, g, h, i, j, k, l)
forall a b c d e g h i j k l m r.
(a -> b -> c -> d -> e -> g -> h -> i -> j -> k -> l -> m -> r)
-> RowDecoder a
-> RowDecoder b
-> RowDecoder c
-> RowDecoder d
-> RowDecoder e
-> RowDecoder g
-> RowDecoder h
-> RowDecoder i
-> RowDecoder j
-> RowDecoder k
-> RowDecoder l
-> RowDecoder m
-> RowDecoder r
lift12RowCalled (,,,,,,,,,,,) RowDecoder a
a RowDecoder b
b RowDecoder c
c RowDecoder d
d RowDecoder e
e RowDecoder f
f RowDecoder g
g RowDecoder h
h RowDecoder i
i RowDecoder j
j RowDecoder k
k RowDecoder l
l
{-# OPAQUE tuple12 #-}
genericFromSqlRow :: forall a. (Generic a, GRowDecoder (Rep a)) => RowDecoder a
genericFromSqlRow :: forall a. (Generic a, GRowDecoder (Rep a)) => RowDecoder a
genericFromSqlRow = case forall (f :: * -> *) p. GRowDecoder f => GDecoder f p
gRowDecoder @(Rep a) @() of
GDecoder RowDecoder a
d -> (a -> a) -> RowDecoder a -> RowDecoder a
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
recordDecoder ((Rep a () -> a
forall a x. Generic a => Rep a x -> a
forall x. Rep a x -> a
to :: Rep a () -> a) (Rep a () -> a) -> (a -> Rep a ()) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a ()
forall a b. Coercible a b => a -> b
coerce) RowDecoder a
d
{-# INLINE genericFromSqlRow #-}
data GDecoder f p = forall a. Coercible a (f p) => GDecoder (RowDecoder a)
class GRowDecoder f where
gRowDecoder :: GDecoder f p
instance (GRowDecoder f, GRowDecoder g) => GRowDecoder (f :*: g) where
gRowDecoder :: forall p. GDecoder (f :*: g) p
gRowDecoder :: forall p. GDecoder (f :*: g) p
gRowDecoder = case forall (f :: * -> *) p. GRowDecoder f => GDecoder f p
gRowDecoder @f @p of
GDecoder RowDecoder a
da -> case forall (f :: * -> *) p. GRowDecoder f => GDecoder f p
gRowDecoder @g @p of
GDecoder RowDecoder a
db -> RowDecoder ((:*:) f g p) -> GDecoder (f :*: g) p
forall (f :: * -> *) p a.
Coercible a (f p) =>
RowDecoder a -> GDecoder f p
GDecoder (RowDecoder a -> RowDecoder a -> RowDecoder ((:*:) f g p)
forall a b (f :: * -> *) (g :: * -> *) p.
(Coercible a (f p), Coercible b (g p)) =>
RowDecoder a -> RowDecoder b -> RowDecoder ((:*:) f g p)
productDecoder RowDecoder a
da RowDecoder a
db :: RowDecoder ((f :*: g) p))
{-# INLINE gRowDecoder #-}
instance GRowDecoder f => GRowDecoder (M1 i c f) where
gRowDecoder :: forall p. GDecoder (M1 i c f) p
gRowDecoder :: forall p. GDecoder (M1 i c f) p
gRowDecoder = case forall (f :: * -> *) p. GRowDecoder f => GDecoder f p
gRowDecoder @f @p of GDecoder RowDecoder a
d -> RowDecoder a -> GDecoder (M1 i c f) p
forall (f :: * -> *) p a.
Coercible a (f p) =>
RowDecoder a -> GDecoder f p
GDecoder RowDecoder a
d
{-# INLINE gRowDecoder #-}
instance FromSqlField a => GRowDecoder (K1 i a) where
gRowDecoder :: forall p. GDecoder (K1 i a) p
gRowDecoder = RowDecoder a -> GDecoder (K1 i a) p
forall (f :: * -> *) p a.
Coercible a (f p) =>
RowDecoder a -> GDecoder f p
GDecoder (forall a. FromSqlField a => RowDecoder a
fieldRowDecoder @a)
{-# INLINE gRowDecoder #-}
productDecoder :: forall a b f g p. (Coercible a (f p), Coercible b (g p))
=> RowDecoder a -> RowDecoder b -> RowDecoder ((f :*: g) p)
productDecoder :: forall a b (f :: * -> *) (g :: * -> *) p.
(Coercible a (f p), Coercible b (g p)) =>
RowDecoder a -> RowDecoder b -> RowDecoder ((:*:) f g p)
productDecoder = (a -> b -> (:*:) f g p)
-> RowDecoder a -> RowDecoder b -> RowDecoder ((:*:) f g p)
forall a b c.
(a -> b -> c) -> RowDecoder a -> RowDecoder b -> RowDecoder c
liftRow (\a
a b
b -> a -> f p
forall a b. Coercible a b => a -> b
coerce a
a f p -> g p -> (:*:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: b -> g p
forall a b. Coercible a b => a -> b
coerce b
b)
{-# NOINLINE productDecoder #-}
recordDecoder :: (a -> b) -> RowDecoder a -> RowDecoder b
recordDecoder :: forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
recordDecoder = (a -> b) -> RowDecoder a -> RowDecoder b
forall a b. (a -> b) -> RowDecoder a -> RowDecoder b
mapRow
{-# NOINLINE recordDecoder #-}
newtype RowDecoderMonadic a = RowDecoderMonadic
{ forall a.
RowDecoderMonadic a
-> TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int)
runRowDecoderMonadic :: TdsContext -> ResultSetInfo -> Int -> B.ByteString -> Int
-> Parser (Either ReadFailure a, Int)
}
instance Functor RowDecoderMonadic where
fmap :: forall a b. (a -> b) -> RowDecoderMonadic a -> RowDecoderMonadic b
fmap a -> b
f (RowDecoderMonadic TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int)
d) = (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int))
-> RowDecoderMonadic b
forall a.
(TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
RowDecoderMonadic ((TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int))
-> RowDecoderMonadic b)
-> (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int))
-> RowDecoderMonadic b
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ResultSetInfo
rs Int
ahead ByteString
bitmap Int
i -> do
(r, j) <- TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int)
d TdsContext
ctx ResultSetInfo
rs Int
ahead ByteString
bitmap Int
i
pure (fmap f r, j)
instance Applicative RowDecoderMonadic where
pure :: forall a. a -> RowDecoderMonadic a
pure a
a = (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
forall a.
(TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
RowDecoderMonadic ((TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a)
-> (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
forall a b. (a -> b) -> a -> b
$ \TdsContext
_ ResultSetInfo
_ Int
_ ByteString
_ Int
i -> (Either ReadFailure a, Int) -> Parser (Either ReadFailure a, Int)
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Either ReadFailure a
forall a b. b -> Either a b
Right a
a, Int
i)
RowDecoderMonadic (a -> b)
mf <*> :: forall a b.
RowDecoderMonadic (a -> b)
-> RowDecoderMonadic a -> RowDecoderMonadic b
<*> RowDecoderMonadic a
ma = RowDecoderMonadic (a -> b)
mf RowDecoderMonadic (a -> b)
-> ((a -> b) -> RowDecoderMonadic b) -> RowDecoderMonadic b
forall a b.
RowDecoderMonadic a
-> (a -> RowDecoderMonadic b) -> RowDecoderMonadic b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a -> b
f -> (a -> b) -> RowDecoderMonadic a -> RowDecoderMonadic b
forall a b. (a -> b) -> RowDecoderMonadic a -> RowDecoderMonadic b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f RowDecoderMonadic a
ma
instance Monad RowDecoderMonadic where
RowDecoderMonadic TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int)
d >>= :: forall a b.
RowDecoderMonadic a
-> (a -> RowDecoderMonadic b) -> RowDecoderMonadic b
>>= a -> RowDecoderMonadic b
k = (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int))
-> RowDecoderMonadic b
forall a.
(TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
RowDecoderMonadic ((TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int))
-> RowDecoderMonadic b)
-> (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int))
-> RowDecoderMonadic b
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ResultSetInfo
rs Int
ahead ByteString
bitmap Int
i -> do
(r, j) <- TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int)
d TdsContext
ctx ResultSetInfo
rs Int
ahead ByteString
bitmap Int
i
case r of
Left ReadFailure
err -> (Either ReadFailure b, Int) -> Parser (Either ReadFailure b, Int)
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReadFailure -> Either ReadFailure b
forall a b. a -> Either a b
Left ReadFailure
err, Int
j)
Right a
a -> RowDecoderMonadic b
-> TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure b, Int)
forall a.
RowDecoderMonadic a
-> TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int)
runRowDecoderMonadic (a -> RowDecoderMonadic b
k a
a) TdsContext
ctx ResultSetInfo
rs Int
ahead ByteString
bitmap Int
j
singleFieldM :: FieldDecoder a -> RowDecoderMonadic a
singleFieldM :: forall a. FieldDecoder a -> RowDecoderMonadic a
singleFieldM = RowDecoder a -> RowDecoderMonadic a
forall a. RowDecoder a -> RowDecoderMonadic a
toMonadicRowDecoder (RowDecoder a -> RowDecoderMonadic a)
-> (FieldDecoder a -> RowDecoder a)
-> FieldDecoder a
-> RowDecoderMonadic a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDecoder a -> RowDecoder a
forall a. FieldDecoder a -> RowDecoder a
singleField
remainingColumns :: RowDecoderMonadic [ColumnInfo]
remainingColumns :: RowDecoderMonadic [ColumnInfo]
remainingColumns = (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure [ColumnInfo], Int))
-> RowDecoderMonadic [ColumnInfo]
forall a.
(TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
RowDecoderMonadic ((TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure [ColumnInfo], Int))
-> RowDecoderMonadic [ColumnInfo])
-> (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure [ColumnInfo], Int))
-> RowDecoderMonadic [ColumnInfo]
forall a b. (a -> b) -> a -> b
$ \TdsContext
_ ResultSetInfo
rs Int
_ ByteString
_ Int
i -> (Either ReadFailure [ColumnInfo], Int)
-> Parser (Either ReadFailure [ColumnInfo], Int)
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ColumnInfo] -> Either ReadFailure [ColumnInfo]
forall a b. b -> Either a b
Right (Int -> [ColumnInfo] -> [ColumnInfo]
forall a. Int -> [a] -> [a]
drop Int
i (ResultSetInfo -> [ColumnInfo]
rsColumns ResultSetInfo
rs)), Int
i)
toMonadicRowDecoder :: RowDecoder a -> RowDecoderMonadic a
toMonadicRowDecoder :: forall a. RowDecoder a -> RowDecoderMonadic a
toMonadicRowDecoder RowDecoder a
dec = (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
forall a.
(TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
RowDecoderMonadic ((TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a)
-> (TdsContext
-> ResultSetInfo
-> Int
-> ByteString
-> Int
-> Parser (Either ReadFailure a, Int))
-> RowDecoderMonadic a
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ResultSetInfo
rs Int
ahead ByteString
bitmap Int
i -> do
let n :: Int
n = RowDecoder a -> Int
forall a. RowDecoder a -> Int
numExpectedColumns RowDecoder a
dec
remaining :: Int
remaining = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i)
if Int
remaining Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n then (Either ReadFailure a, Int) -> Parser (Either ReadFailure a, Int)
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left (DecodeError -> ReadFailure
DecodeFailed (Maybe Text -> [Char] -> DecodeError
DecodeError Maybe Text
forall a. Maybe a
Nothing
(if Int
remaining Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 then [Char]
"no more columns" else
[Char]
"result has " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
remaining [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" column(s) but the row type expects " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n))), Int
i)
else case RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
forall a.
RowDecoder a
-> TdsContext
-> ResultSetInfo
-> Int
-> Either DecodeError (RowPart a)
compileRowAt RowDecoder a
dec TdsContext
ctx ResultSetInfo
rs Int
i of
Left DecodeError
err -> (Either ReadFailure a, Int) -> Parser (Either ReadFailure a, Int)
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left (DecodeError -> ReadFailure
DecodeFailed DecodeError
err), Int
i)
Right (RowPart Int -> Prepared (Recipe ByteString a)
prepare) | Prepared Recipe ByteString a
read <- Int -> Prepared (Recipe ByteString a)
prepare Int
ahead -> do
result <- Recipe () a -> Recipe () (Either ReadFailure a)
forall env a. Recipe env a -> Recipe env (Either ReadFailure a)
P.attempt (ByteString -> Recipe ByteString a -> Recipe () a
forall env a. env -> Recipe env a -> Parser a
P.withEnv ByteString
bitmap Recipe ByteString a
read)
pure $ case result of
Left ReadFailure
err -> (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left ReadFailure
err, ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs)
Right a
value -> (a -> Either ReadFailure a
forall a b. b -> Either a b
Right a
value, Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n)
sqlRowDecoder :: RowDecoderMonadic SqlRow
sqlRowDecoder :: RowDecoderMonadic SqlRow
sqlRowDecoder = do
cols <- RowDecoderMonadic [ColumnInfo]
remainingColumns
SqlRow cols <$> mapM (const (singleFieldM sqlValueDecoder)) cols
compileMonadicRowDecoder :: RowDecoderMonadic a -> TdsContext -> [ColumnInfo] -> CompiledRow a
compileMonadicRowDecoder :: forall a.
RowDecoderMonadic a -> TdsContext -> [ColumnInfo] -> CompiledRow a
compileMonadicRowDecoder RowDecoderMonadic a
dec TdsContext
ctx [ColumnInfo]
cols = (Int -> Prepared (Parser a)) -> CompiledRow a
forall a. (Int -> Prepared (Parser a)) -> CompiledRow a
CompiledRow ((Int -> Prepared (Parser a)) -> CompiledRow a)
-> (Int -> Prepared (Parser a)) -> CompiledRow a
forall a b. (a -> b) -> a -> b
$ \Int
ahead -> Parser a -> Prepared (Parser a)
forall a. a -> Prepared a
Prepared (Parser a -> Prepared (Parser a))
-> Parser a -> Prepared (Parser a)
forall a b. (a -> b) -> a -> b
$ do
bitmap <- Int -> Parser ByteString
rowBitmap Int
n
(result, consumed) <- runRowDecoderMonadic dec ctx rs ahead bitmap 0
skipCells bitmap (drop consumed (rsCells rs))
case result of
Left ReadFailure
err -> ReadFailure -> Parser a
forall env a. ReadFailure -> Recipe env a
P.failValue ReadFailure
err
Right a
a | Int
consumed Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n -> a -> Parser a
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
Right a
_ -> ReadFailure -> Parser a
forall env a. ReadFailure -> Recipe env a
P.failValue (ReadFailure -> Parser a) -> ReadFailure -> Parser a
forall a b. (a -> b) -> a -> b
$ DecodeError -> ReadFailure
DecodeFailed (DecodeError -> ReadFailure) -> DecodeError -> ReadFailure
forall a b. (a -> b) -> a -> b
$ Maybe Text -> [Char] -> DecodeError
DecodeError Maybe Text
forall a. Maybe a
Nothing ([Char] -> DecodeError) -> [Char] -> DecodeError
forall a b. (a -> b) -> a -> b
$
[Char]
"result has " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" column(s) but the row decoder consumed " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
consumed
where
rs :: ResultSetInfo
rs = [ColumnInfo] -> ResultSetInfo
compileResultSet [ColumnInfo]
cols
n :: Int
n = ResultSetInfo -> Int
rsColumnCount ResultSetInfo
rs
data ValueStream = ValueStream
{ ValueStream -> ColumnInfo
valueColumn :: !ColumnInfo
, ValueStream -> Maybe Int64
valueLength :: !(Maybe Int64)
, ValueStream -> Stream (Of ByteString) IO ()
valueChunks :: Stream (Of B.ByteString) IO ()
}
streamField :: (ValueStream -> IO a) -> FieldDecoder a
streamField :: forall a. (ValueStream -> IO a) -> FieldDecoder a
streamField ValueStream -> IO a
use = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a b. (a -> b) -> a -> b
$ \TdsContext
_ ColumnInfo
col -> CellDecoder a -> Either [Char] (CellDecoder a)
forall a b. b -> Either a b
Right (CellDecoder a -> Either [Char] (CellDecoder a))
-> CellDecoder a -> Either [Char] (CellDecoder a)
forall a b. (a -> b) -> a -> b
$ (StreamedValue -> Parser (Either ReadFailure a)) -> CellDecoder a
forall a.
(StreamedValue -> Parser (Either ReadFailure a)) -> CellDecoder a
StreamingCell ((StreamedValue -> Parser (Either ReadFailure a)) -> CellDecoder a)
-> (StreamedValue -> Parser (Either ReadFailure a))
-> CellDecoder a
forall a b. (a -> b) -> a -> b
$ \case
StreamedValue
StreamedNull -> Either ReadFailure a -> Parser (Either ReadFailure a)
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left (DecodeError -> ReadFailure
DecodeFailed (Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col)) [Char]
"SQL NULL cannot be streamed; use nullableField")))
StreamedWhole ValueBytes
bytes -> Either ReadFailure a
-> (a -> Either ReadFailure a) -> Maybe a -> Either ReadFailure a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left ReadFailure
ReadDiscarded) a -> Either ReadFailure a
forall a b. b -> Either a b
Right
(Maybe a -> Either ReadFailure a)
-> Recipe () (Maybe a) -> Parser (Either ReadFailure a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString
-> (Stream (Of ByteString) IO () -> IO a) -> Recipe () (Maybe a)
forall a.
ByteString
-> (Stream (Of ByteString) IO () -> IO a) -> Parser (Maybe a)
P.consumeWhole (ValueBytes -> ByteString
P.keepBytes ValueBytes
bytes) (ValueStream -> IO a
use (ValueStream -> IO a)
-> (Stream (Of ByteString) IO () -> ValueStream)
-> Stream (Of ByteString) IO ()
-> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ColumnInfo
-> Maybe Int64 -> Stream (Of ByteString) IO () -> ValueStream
ValueStream ColumnInfo
col (Int64 -> Maybe Int64
forall a. a -> Maybe a
Just (Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
B.length (ValueBytes -> ByteString
P.valueBytes ValueBytes
bytes)))))
StreamedBytes Maybe Int64
total Stream (Of ByteString) (Recipe ()) ()
chunks -> Either ReadFailure a
-> (a -> Either ReadFailure a) -> Maybe a -> Either ReadFailure a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left ReadFailure
ReadDiscarded) a -> Either ReadFailure a
forall a b. b -> Either a b
Right (Maybe a -> Either ReadFailure a)
-> Recipe () (Maybe a) -> Parser (Either ReadFailure a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Stream (Of ByteString) (Recipe ()) ()
-> (Stream (Of ByteString) IO () -> IO a) -> Recipe () (Maybe a)
forall a.
Stream (Of ByteString) (Recipe ()) ()
-> (Stream (Of ByteString) IO () -> IO a) -> Parser (Maybe a)
P.consume Stream (Of ByteString) (Recipe ()) ()
chunks (ValueStream -> IO a
use (ValueStream -> IO a)
-> (Stream (Of ByteString) IO () -> ValueStream)
-> Stream (Of ByteString) IO ()
-> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ColumnInfo
-> Maybe Int64 -> Stream (Of ByteString) IO () -> ValueStream
ValueStream ColumnInfo
col Maybe Int64
total)
streamTextField :: (ColumnInfo -> Stream (Of Text) IO () -> IO a) -> FieldDecoder a
streamTextField :: forall a.
(ColumnInfo -> Stream (Of Text) IO () -> IO a) -> FieldDecoder a
streamTextField ColumnInfo -> Stream (Of Text) IO () -> IO a
use = (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a.
(TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
FieldDecoder ((TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a)
-> (TdsContext -> ColumnInfo -> Either [Char] (CellDecoder a))
-> FieldDecoder a
forall a b. (a -> b) -> a -> b
$ \TdsContext
ctx ColumnInfo
col -> do
encoding <- TypeInfo -> Either [Char] TextEncoding
textEncodingOf (ColumnInfo -> TypeInfo
columnType ColumnInfo
col)
compileField (streamField (\ValueStream
v -> ColumnInfo -> Stream (Of Text) IO () -> IO a
use ColumnInfo
col (TextEncoding
-> Stream (Of ByteString) IO () -> Stream (Of Text) IO ()
forall (m :: * -> *) r.
Monad m =>
TextEncoding -> Stream (Of ByteString) m r -> Stream (Of Text) m r
decodeTextChunks TextEncoding
encoding (ValueStream -> Stream (Of ByteString) IO ()
valueChunks ValueStream
v)))) ctx col
decodeTextChunks :: Monad m => TextEncoding -> Stream (Of B.ByteString) m r -> Stream (Of Text) m r
decodeTextChunks :: forall (m :: * -> *) r.
Monad m =>
TextEncoding -> Stream (Of ByteString) m r -> Stream (Of Text) m r
decodeTextChunks TextEncoding
TextUtf16 = Stream (Of ByteString) m r -> Stream (Of Text) m r
forall (m :: * -> *) r.
Monad m =>
Stream (Of ByteString) m r -> Stream (Of Text) m r
Utf16.decodeUtf16Chunks
decodeTextChunks (TextCodec TextCodec
codec) = TextCodec -> Stream (Of ByteString) m r -> Stream (Of Text) m r
forall (m :: * -> *) r.
Monad m =>
TextCodec -> Stream (Of ByteString) m r -> Stream (Of Text) m r
decodeCodecChunks TextCodec
codec
skipRowDecoder :: [ColumnInfo] -> CompiledRow ()
skipRowDecoder :: [ColumnInfo] -> CompiledRow ()
skipRowDecoder [ColumnInfo]
cols =
let info :: ResultSetInfo
info = [ColumnInfo] -> ResultSetInfo
compileResultSet [ColumnInfo]
cols
in (Int -> Prepared (Parser ())) -> CompiledRow ()
forall a. (Int -> Prepared (Parser a)) -> CompiledRow a
CompiledRow ((Int -> Prepared (Parser ())) -> CompiledRow ())
-> (Int -> Prepared (Parser ())) -> CompiledRow ()
forall a b. (a -> b) -> a -> b
$ \Int
_ -> Parser () -> Prepared (Parser ())
forall a. a -> Prepared a
Prepared (Parser () -> Prepared (Parser ()))
-> Parser () -> Prepared (Parser ())
forall a b. (a -> b) -> a -> b
$ do
bitmap <- Int -> Parser ByteString
rowBitmap (ResultSetInfo -> Int
rsColumnCount ResultSetInfo
info)
skipCells bitmap (rsCells info)
readCellRecipe :: ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
readCellRecipe :: forall a. ColumnInfo -> CellDecoder a -> Int -> Cell -> Parser a
readCellRecipe ColumnInfo
col CellDecoder a
decoder Int
ahead Cell
cell = case CellDecoder a
decoder of
CellDecoder Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned -> Either [Char] a -> ValueReader a -> ValueReader a -> Parser a
whole Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned
FoldingCell Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold
| Cell -> Bool
withinLimit Cell
cell -> Either [Char] a -> ValueReader a -> ValueReader a -> Parser a
whole Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned
| Bool
otherwise -> ColumnInfo
-> Either [Char] a
-> ValueReader a
-> ValueReader a
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> Int
-> Cell
-> Parser a
forall a.
ColumnInfo
-> Either [Char] a
-> ValueReader a
-> ValueReader a
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> Int
-> Cell
-> Parser a
foldingCellRecipe ColumnInfo
col Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold Int
ahead Cell
cell
StreamingCell StreamedValue -> Parser (Either ReadFailure a)
read -> ColumnInfo
-> (StreamedValue -> Parser (Either ReadFailure a))
-> Int
-> Cell
-> Parser a
forall a.
ColumnInfo
-> (StreamedValue -> Parser (Either ReadFailure a))
-> Int
-> Cell
-> Parser a
streamingCellRecipe ColumnInfo
col StreamedValue -> Parser (Either ReadFailure a)
read Int
ahead Cell
cell
where
whole :: Either [Char] a -> ValueReader a -> ValueReader a -> Parser a
whole Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned = case Cell
cell of
Sized Int
n -> Int
-> Int
-> (ByteString -> Either ReadFailure a)
-> (ByteString -> Either ReadFailure a)
-> Parser a
forall a.
Int
-> Int
-> (ByteString -> Either ReadFailure a)
-> (ByteString -> Either ReadFailure a)
-> Parser a
P.convertBytes Int
ahead Int
n (Either [Char] a -> Either ReadFailure a
failed (Either [Char] a -> Either ReadFailure a)
-> ValueReader a -> ByteString -> Either ReadFailure a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
borrowed) (Either [Char] a -> Either ReadFailure a
failed (Either [Char] a -> Either ReadFailure a)
-> ValueReader a -> ByteString -> Either ReadFailure a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueReader a
owned)
Cell
_ -> do
value <- Int -> Cell -> Parser WholeValue
wholeValueBytes Int
ahead Cell
cell
case value of
WholeValue
DiscardedValue -> ReadFailure -> Parser a
forall env a. ReadFailure -> Recipe env a
P.failValue ReadFailure
ReadDiscarded
WholeValue
NullValue -> Either [Char] a -> Parser a
named Either [Char] a
onNull
PresentValue (P.Borrowed ByteString
bytes) -> Either [Char] a -> Parser a
named (ValueReader a
borrowed ByteString
bytes)
PresentValue (P.Owned ByteString
bytes) -> Either [Char] a -> Parser a
named (ValueReader a
owned ByteString
bytes)
failed :: Either [Char] a -> Either ReadFailure a
failed = ([Char] -> Either ReadFailure a)
-> (a -> Either ReadFailure a)
-> Either [Char] a
-> Either ReadFailure a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left (ReadFailure -> Either ReadFailure a)
-> ([Char] -> ReadFailure) -> [Char] -> Either ReadFailure a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DecodeError -> ReadFailure
DecodeFailed (DecodeError -> ReadFailure)
-> ([Char] -> DecodeError) -> [Char] -> ReadFailure
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col))) a -> Either ReadFailure a
forall a b. b -> Either a b
Right
named :: Either [Char] a -> Parser a
named = (ReadFailure -> Parser a)
-> (a -> Parser a) -> Either ReadFailure a -> Parser a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ReadFailure -> Parser a
forall env a. ReadFailure -> Recipe env a
P.failValue a -> Parser a
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ReadFailure a -> Parser a)
-> (Either [Char] a -> Either ReadFailure a)
-> Either [Char] a
-> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either [Char] a -> Either ReadFailure a
failed
{-# INLINE readCellRecipe #-}
presentCell :: ColumnInfo -> Either String a -> ValueReader a -> ValueReader a -> WholeValue -> Parser a
presentCell :: forall a.
ColumnInfo
-> Either [Char] a
-> ValueReader a
-> ValueReader a
-> WholeValue
-> Parser a
presentCell ColumnInfo
col Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned = \case
WholeValue
DiscardedValue -> ReadFailure -> Parser a
forall env a. ReadFailure -> Recipe env a
P.failValue ReadFailure
ReadDiscarded
WholeValue
NullValue -> Either [Char] a -> Parser a
named Either [Char] a
onNull
PresentValue (P.Borrowed ByteString
bytes) -> Either [Char] a -> Parser a
named (ValueReader a
borrowed ByteString
bytes)
PresentValue (P.Owned ByteString
bytes) -> Either [Char] a -> Parser a
named (ValueReader a
owned ByteString
bytes)
where named :: Either [Char] a -> Parser a
named = (ReadFailure -> Parser a)
-> (a -> Parser a) -> Either ReadFailure a -> Parser a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ReadFailure -> Parser a
forall env a. ReadFailure -> Recipe env a
P.failValue a -> Parser a
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ReadFailure a -> Parser a)
-> (Either [Char] a -> Either ReadFailure a)
-> Either [Char] a
-> Parser a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ColumnInfo -> Either [Char] a -> Either ReadFailure a
forall a. ColumnInfo -> Either [Char] a -> Either ReadFailure a
failed ColumnInfo
col
{-# INLINE presentCell #-}
failed :: ColumnInfo -> Either String a -> Either ReadFailure a
failed :: forall a. ColumnInfo -> Either [Char] a -> Either ReadFailure a
failed ColumnInfo
col = ([Char] -> Either ReadFailure a)
-> (a -> Either ReadFailure a)
-> Either [Char] a
-> Either ReadFailure a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ReadFailure -> Either ReadFailure a
forall a b. a -> Either a b
Left (ReadFailure -> Either ReadFailure a)
-> ([Char] -> ReadFailure) -> [Char] -> Either ReadFailure a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DecodeError -> ReadFailure
DecodeFailed (DecodeError -> ReadFailure)
-> ([Char] -> DecodeError) -> [Char] -> ReadFailure
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> [Char] -> DecodeError
DecodeError (Text -> Maybe Text
forall a. a -> Maybe a
Just (ColumnInfo -> Text
columnName ColumnInfo
col))) a -> Either ReadFailure a
forall a b. b -> Either a b
Right
{-# INLINE failed #-}
withinLimit :: Cell -> Bool
withinLimit :: Cell -> Bool
withinLimit = \case
Sized Int
n -> Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
streamWholeLimit
Unsized (Just Word64
total) -> Word64
total Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
streamWholeLimit
Unsized Maybe Word64
Nothing -> Bool
False
Cell
NullCell -> Bool
True
{-# INLINE withinLimit #-}
foldingCellRecipe :: ColumnInfo -> Either String a -> ValueReader a -> ValueReader a
-> (Stream (Of B.ByteString) Parser () -> Parser (Either ReadFailure a)) -> Int -> Cell -> Parser a
foldingCellRecipe :: forall a.
ColumnInfo
-> Either [Char] a
-> ValueReader a
-> ValueReader a
-> (Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a))
-> Int
-> Cell
-> Parser a
foldingCellRecipe ColumnInfo
col Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold Int
ahead Cell
cell = Int
-> Int
-> Cell
-> Parser
(Either (Stream (Of ByteString) (Recipe ()) ()) WholeValue)
boundedValue Int
ahead Int
streamWholeLimit Cell
cell Parser (Either (Stream (Of ByteString) (Recipe ()) ()) WholeValue)
-> (Either (Stream (Of ByteString) (Recipe ()) ()) WholeValue
-> Recipe () a)
-> Recipe () a
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right WholeValue
value -> ColumnInfo
-> Either [Char] a
-> ValueReader a
-> ValueReader a
-> WholeValue
-> Recipe () a
forall a.
ColumnInfo
-> Either [Char] a
-> ValueReader a
-> ValueReader a
-> WholeValue
-> Parser a
presentCell ColumnInfo
col Either [Char] a
onNull ValueReader a
borrowed ValueReader a
owned WholeValue
value
Left Stream (Of ByteString) (Recipe ()) ()
chunks -> Stream (Of ByteString) (Recipe ()) ()
-> Parser (Either ReadFailure a)
fold Stream (Of ByteString) (Recipe ()) ()
chunks Parser (Either ReadFailure a)
-> (Either ReadFailure a -> Recipe () a) -> Recipe () a
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ReadFailure -> Recipe () a)
-> (a -> Recipe () a) -> Either ReadFailure a -> Recipe () a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ReadFailure -> Recipe () a
forall env a. ReadFailure -> Recipe env a
P.failValue a -> Recipe () a
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# NOINLINE foldingCellRecipe #-}
streamingCellRecipe :: ColumnInfo -> (StreamedValue -> Parser (Either ReadFailure a)) -> Int -> Cell -> Parser a
streamingCellRecipe :: forall a.
ColumnInfo
-> (StreamedValue -> Parser (Either ReadFailure a))
-> Int
-> Cell
-> Parser a
streamingCellRecipe ColumnInfo
_ StreamedValue -> Parser (Either ReadFailure a)
read Int
ahead Cell
cell = Recipe () StreamedValue
streamed Recipe () StreamedValue
-> (StreamedValue -> Parser (Either ReadFailure a))
-> Parser (Either ReadFailure a)
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= StreamedValue -> Parser (Either ReadFailure a)
read Parser (Either ReadFailure a)
-> (Either ReadFailure a -> Recipe () a) -> Recipe () a
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ReadFailure -> Recipe () a)
-> (a -> Recipe () a) -> Either ReadFailure a -> Recipe () a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ReadFailure -> Recipe () a
forall env a. ReadFailure -> Recipe env a
P.failValue a -> Recipe () a
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
where
streamed :: Recipe () StreamedValue
streamed = Int
-> Int
-> Cell
-> Parser
(Either (Stream (Of ByteString) (Recipe ()) ()) WholeValue)
boundedValue Int
ahead Int
streamWholeLimit Cell
cell Parser (Either (Stream (Of ByteString) (Recipe ()) ()) WholeValue)
-> (Either (Stream (Of ByteString) (Recipe ()) ()) WholeValue
-> Recipe () StreamedValue)
-> Recipe () StreamedValue
forall a b. Recipe () a -> (a -> Recipe () b) -> Recipe () b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right WholeValue
NullValue -> StreamedValue -> Recipe () StreamedValue
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StreamedValue
StreamedNull
Right (PresentValue ValueBytes
bytes) -> StreamedValue -> Recipe () StreamedValue
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ValueBytes -> StreamedValue
StreamedWhole ValueBytes
bytes)
Right WholeValue
DiscardedValue -> ReadFailure -> Recipe () StreamedValue
forall env a. ReadFailure -> Recipe env a
P.failValue ReadFailure
ReadDiscarded
Left Stream (Of ByteString) (Recipe ()) ()
chunks -> StreamedValue -> Recipe () StreamedValue
forall a. a -> Recipe () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Int64
-> Stream (Of ByteString) (Recipe ()) () -> StreamedValue
StreamedBytes (Cell -> Maybe Int64
cellLength Cell
cell) Stream (Of ByteString) (Recipe ()) ()
chunks)
{-# NOINLINE streamingCellRecipe #-}
decodeColumnChunks :: Monad m => TypeInfo -> Either String (Stream (Of B.ByteString) m r -> Stream (Of Text) m r)
decodeColumnChunks :: forall (m :: * -> *) r.
Monad m =>
TypeInfo
-> Either
[Char] (Stream (Of ByteString) m r -> Stream (Of Text) m r)
decodeColumnChunks TypeInfo
ti = TextEncoding -> Stream (Of ByteString) m r -> Stream (Of Text) m r
forall (m :: * -> *) r.
Monad m =>
TextEncoding -> Stream (Of ByteString) m r -> Stream (Of Text) m r
decodeTextChunks (TextEncoding
-> Stream (Of ByteString) m r -> Stream (Of Text) m r)
-> Either [Char] TextEncoding
-> Either
[Char] (Stream (Of ByteString) m r -> Stream (Of Text) m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TypeInfo -> Either [Char] TextEncoding
textEncodingOf TypeInfo
ti