{-# LANGUAGE
    OverloadedStrings
  , TemplateHaskell
  , TypeFamilyDependencies
#-}
{-# LANGUAGE ConstraintKinds #-}

module ClickHaskell.Columns where

-- Internal dependencies
import ClickHaskell.DbTypes
import ClickHaskell.DeSerialization (Serializable (..), DeserializableColumn (..), DeserializableColumns)
import ClickHaskell.Versioning (ProtocolRevision)

-- GHC included
import Data.Binary (Get)
import Data.ByteString.Builder (Builder)
import Data.Kind (Type)
import GHC.Generics
import GHC.TypeLits (ErrorMessage (..), Symbol, TypeError)

-- * Columns

emptyColumns :: Columns '[]
emptyColumns :: Columns '[]
emptyColumns = Columns '[]
Empty

rowsCount ::  Columns columns -> UVarInt
rowsCount :: forall (columns :: [*]). Columns columns -> UVarInt
rowsCount (AddColumn Column name chType
col Columns columns1
_) = Column name chType -> UVarInt
forall (name :: Symbol) chType. Column name chType -> UVarInt
columnSize Column name chType
col
rowsCount Columns columns
Empty = UVarInt
0

{-# INLINE [0] appendColumn #-}
appendColumn
  :: KnownColumn (Column name chType)
  => Column name chType
  -> Columns columns
  -> Columns (Column name chType ': columns)
appendColumn :: forall (name :: Symbol) chType (columns :: [*]).
KnownColumn (Column name chType) =>
Column name chType
-> Columns columns -> Columns (Column name chType : columns)
appendColumn = Column name chType
-> Columns columns -> Columns (Column name chType : columns)
forall (name :: Symbol) chType (columns :: [*]).
KnownColumn (Column name chType) =>
Column name chType
-> Columns columns -> Columns (Column name chType : columns)
AddColumn


-- ** Columns extraction helper

class
  HasColumns hasColumns
  where
  type GetColumns hasColumns :: [Type]

instance HasColumns (Columns columns)
  where
  type GetColumns (Columns columns) = columns


-- ** Take column by name from list of columns

type family
  TakeColumn (name :: Symbol) (columns :: [Type]) :: (Type, [Type])
  where
  TakeColumn name columns = GoTakeColumn name columns '[]

type family
  GoTakeColumn name (columns :: [Type]) (acc :: [Type]) :: (Type, [Type])
  where
  GoTakeColumn name (Column name chType ': columns) acc = '(Column name chType, acc ++ columns)
  GoTakeColumn name (Column name1 chType ': columns) acc = (GoTakeColumn name columns (Column name1 chType ': acc))
  GoTakeColumn name '[]                 acc = TypeError
    (    'Text "There is no column \"" :<>: 'Text name :<>: 'Text "\" in table"
    :$$: 'Text "You can't use this field"
    )

type family
  (++) (list1 :: [Type]) (list2 :: [Type]) :: [Type]
  where
  (++) '[]            list = list
  (++) (head ': tail) list = tail ++ (head ': list)




-- * To columns generic convertion

type GenericWritable record columns =
  ( Generic record
  , GWritable columns (Rep record)
  )

class
  ( HasColumns (Columns (GetColumns columns))
  , Serializable (Columns (GetColumns columns))
  , DeserializableColumns (Columns (GetColumns columns))
  ) =>
  WritableInto columns record
  where
  default serializeRecords :: GenericWritable record (GetColumns columns) => ProtocolRevision -> UVarInt -> [record] -> Builder
  serializeRecords :: ProtocolRevision -> UVarInt -> [record] -> Builder
  serializeRecords ProtocolRevision
rev UVarInt
size = forall (columns :: [*]) (f :: * -> *) p.
GWritable columns f =>
ProtocolRevision -> UVarInt -> [f p] -> Builder
gSerializeRecords @(GetColumns columns) ProtocolRevision
rev UVarInt
size ([Rep record Any] -> Builder)
-> ([record] -> [Rep record Any]) -> [record] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (record -> Rep record Any) -> [record] -> [Rep record Any]
forall a b. (a -> b) -> [a] -> [b]
map record -> Rep record Any
forall x. record -> Rep record x
forall a x. Generic a => a -> Rep a x
from

  default writingColumns :: GenericWritable record (GetColumns columns) => Builder
  writingColumns :: Builder
  writingColumns = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
Builder
gWritingColumns @(GetColumns columns) @(Rep record)

  default columnsCount :: GenericWritable record (GetColumns columns) => UVarInt
  columnsCount :: UVarInt
  columnsCount = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
UVarInt
gColumnsCount @(GetColumns columns) @(Rep record)

class GWritable (columns :: [Type]) f
  where
  gSerializeRecords :: ProtocolRevision -> UVarInt -> [f p] -> Builder
  gWritingColumns :: Builder
  gColumnsCount :: UVarInt

instance
  GWritable columns f
  =>
  GWritable columns (D1 c (C1 c2 f))
  where
  {-# INLINE gSerializeRecords #-}
  gSerializeRecords :: forall p.
ProtocolRevision -> UVarInt -> [D1 c (C1 c2 f) p] -> Builder
gSerializeRecords ProtocolRevision
rev UVarInt
size = forall (columns :: [*]) (f :: * -> *) p.
GWritable columns f =>
ProtocolRevision -> UVarInt -> [f p] -> Builder
gSerializeRecords @columns ProtocolRevision
rev UVarInt
size ([f p] -> Builder)
-> ([D1 c (C1 c2 f) p] -> [f p]) -> [D1 c (C1 c2 f) p] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (D1 c (C1 c2 f) p -> f p) -> [D1 c (C1 c2 f) p] -> [f p]
forall a b. (a -> b) -> [a] -> [b]
map (M1 C c2 f p -> f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1 (M1 C c2 f p -> f p)
-> (D1 c (C1 c2 f) p -> M1 C c2 f p) -> D1 c (C1 c2 f) p -> f p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. D1 c (C1 c2 f) p -> M1 C c2 f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1)
  {-# INLINE gWritingColumns #-}
  gWritingColumns :: Builder
gWritingColumns = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
Builder
gWritingColumns @columns @f
  gColumnsCount :: UVarInt
gColumnsCount = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
UVarInt
gColumnsCount @columns @f

instance
  GWritable columns (left1 :*: (left2 :*: right))
  =>
  GWritable columns ((left1 :*: left2) :*: right)
  where
  {-# INLINE gSerializeRecords #-}
  gSerializeRecords :: forall p.
ProtocolRevision
-> UVarInt -> [(:*:) (left1 :*: left2) right p] -> Builder
gSerializeRecords ProtocolRevision
rev UVarInt
size = forall (columns :: [*]) (f :: * -> *) p.
GWritable columns f =>
ProtocolRevision -> UVarInt -> [f p] -> Builder
gSerializeRecords @columns ProtocolRevision
rev UVarInt
size ([(:*:) left1 (left2 :*: right) p] -> Builder)
-> ([(:*:) (left1 :*: left2) right p]
    -> [(:*:) left1 (left2 :*: right) p])
-> [(:*:) (left1 :*: left2) right p]
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((:*:) (left1 :*: left2) right p
 -> (:*:) left1 (left2 :*: right) p)
-> [(:*:) (left1 :*: left2) right p]
-> [(:*:) left1 (left2 :*: right) p]
forall a b. (a -> b) -> [a] -> [b]
map (\((left1 p
l1 :*: left2 p
l2) :*: right p
r) -> left1 p
l1 left1 p -> (:*:) left2 right p -> (:*:) left1 (left2 :*: right) p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (left2 p
l2 left2 p -> right p -> (:*:) left2 right p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: right p
r))
  {-# INLINE gWritingColumns #-}
  gWritingColumns :: Builder
gWritingColumns = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
Builder
gWritingColumns @columns @(left1 :*: (left2 :*: right))
  gColumnsCount :: UVarInt
gColumnsCount = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
UVarInt
gColumnsCount @columns @(left1 :*: (left2 :*: right))

instance
  ( GWritable '[Column name chType] (S1 (MetaSel (Just name) a b f) rec)
  , GWritable restColumns right
  , '(Column name chType, restColumns)~ TakeColumn name columns
  )
  =>
  GWritable columns (S1 (MetaSel (Just name) a b f) rec :*: right)
  where
  {-# INLINE gSerializeRecords #-}
  gSerializeRecords :: forall p.
ProtocolRevision
-> UVarInt
-> [(:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p]
-> Builder
gSerializeRecords ProtocolRevision
rev UVarInt
size
    = (\([M1 S ('MetaSel ('Just name) a b f) rec p]
a, [right p]
b) -> forall (columns :: [*]) (f :: * -> *) p.
GWritable columns f =>
ProtocolRevision -> UVarInt -> [f p] -> Builder
gSerializeRecords @'[Column name chType] ProtocolRevision
rev UVarInt
size [M1 S ('MetaSel ('Just name) a b f) rec p]
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) (f :: * -> *) p.
GWritable columns f =>
ProtocolRevision -> UVarInt -> [f p] -> Builder
gSerializeRecords @restColumns ProtocolRevision
rev UVarInt
size [right p]
b)
    (([M1 S ('MetaSel ('Just name) a b f) rec p], [right p])
 -> Builder)
-> ([(:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p]
    -> ([M1 S ('MetaSel ('Just name) a b f) rec p], [right p]))
-> [(:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p]
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(M1 S ('MetaSel ('Just name) a b f) rec p, right p)]
-> ([M1 S ('MetaSel ('Just name) a b f) rec p], [right p])
forall a b. [(a, b)] -> ([a], [b])
unzip ([(M1 S ('MetaSel ('Just name) a b f) rec p, right p)]
 -> ([M1 S ('MetaSel ('Just name) a b f) rec p], [right p]))
-> ([(:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p]
    -> [(M1 S ('MetaSel ('Just name) a b f) rec p, right p)])
-> [(:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p]
-> ([M1 S ('MetaSel ('Just name) a b f) rec p], [right p])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p
 -> (M1 S ('MetaSel ('Just name) a b f) rec p, right p))
-> [(:*:) (S1 ('MetaSel ('Just name) a b f) rec) right p]
-> [(M1 S ('MetaSel ('Just name) a b f) rec p, right p)]
forall a b. (a -> b) -> [a] -> [b]
map (\(M1 S ('MetaSel ('Just name) a b f) rec p
l :*: right p
r) -> (M1 S ('MetaSel ('Just name) a b f) rec p
l, right p
r))

  {-# INLINE gWritingColumns #-}
  gWritingColumns :: Builder
gWritingColumns =
    forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
Builder
gWritingColumns @'[Column name chType] @(S1 (MetaSel (Just name) a b f) rec)
    Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
", " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
Builder
gWritingColumns @restColumns @right
  gColumnsCount :: UVarInt
gColumnsCount = forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
UVarInt
gColumnsCount @'[Column name chType] @(S1 (MetaSel (Just name) a b f) rec) UVarInt -> UVarInt -> UVarInt
forall a. Num a => a -> a -> a
+ forall (columns :: [*]) (f :: * -> *).
GWritable columns f =>
UVarInt
gColumnsCount @restColumns @right

instance {-# OVERLAPPING #-}
  ( KnownColumn (Column name chType)
  , ToChType chType inputType
  , Serializable (Column name chType)
  , '(Column name chType, restColumns) ~ TakeColumn name columns
  ) =>
  GWritable columns (S1 (MetaSel (Just name) a b f) (Rec0 inputType))
  where
  {-# INLINE gSerializeRecords #-}
  gSerializeRecords :: forall p.
ProtocolRevision
-> UVarInt
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
-> Builder
gSerializeRecords ProtocolRevision
rev UVarInt
size = ProtocolRevision -> Column name chType -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (Column name chType -> Builder)
-> ([S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
    -> Column name chType)
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall column.
KnownColumn column =>
UVarInt
-> [GetColumnType column]
-> Column (GetColumnName column) (GetColumnType column)
mkColumn @(Column name chType) UVarInt
size ([chType] -> Column name chType)
-> ([S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
    -> [chType])
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
-> Column name chType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p -> chType)
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
-> [chType]
forall a b. (a -> b) -> [a] -> [b]
map (inputType -> chType
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (inputType -> chType)
-> (S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
    -> inputType)
-> S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
-> chType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. K1 R inputType p -> inputType
forall k i c (p :: k). K1 i c p -> c
unK1 (K1 R inputType p -> inputType)
-> (S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
    -> K1 R inputType p)
-> S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
-> inputType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
-> K1 R inputType p
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1)
  {-# INLINE gWritingColumns #-}
  gWritingColumns :: Builder
gWritingColumns = forall column. KnownColumn column => Builder
renderColumnName @(Column name chType)
  gColumnsCount :: UVarInt
gColumnsCount = UVarInt
1




-- * From columns generic convertion

-- ** Reading

type GenericReadable record hasColumns =
  ( Generic record
  , GReadable (GetColumns hasColumns) (Rep record)
  )

class
  ( HasColumns hasColumns
  , DeserializableColumns (Columns (GetColumns hasColumns))
  ) =>
  ReadableFrom hasColumns record
  where
  default deserializeColumns :: GenericReadable record hasColumns => ProtocolRevision -> UVarInt -> Get [record]
  deserializeColumns :: ProtocolRevision -> UVarInt -> Get [record]
  deserializeColumns ProtocolRevision
rev UVarInt
size = (Rep record Any -> record) -> [Rep record Any] -> [record]
forall a b. (a -> b) -> [a] -> [b]
map Rep record Any -> record
forall a x. Generic a => Rep a x -> a
forall x. Rep record x -> record
to ([Rep record Any] -> [record])
-> Get [Rep record Any] -> Get [record]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (columns :: [*]) (f :: * -> *) p.
GReadable columns f =>
ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @(GetColumns hasColumns) ProtocolRevision
rev UVarInt
size

  default readingColumns :: GenericReadable record hasColumns => Builder
  readingColumns :: Builder
  readingColumns = forall (columns :: [*]) (f :: * -> *).
GReadable columns f =>
Builder
gReadingColumns @(GetColumns hasColumns) @(Rep record)


class GReadable (columns :: [Type]) f
  where
  gFromColumns :: ProtocolRevision -> UVarInt -> Get [f p]
  gReadingColumns :: Builder

instance
  GReadable columns f
  =>
  GReadable columns (D1 c (C1 c2 f))
  where
  {-# INLINE gFromColumns #-}
  gFromColumns :: forall p. ProtocolRevision -> UVarInt -> Get [D1 c (C1 c2 f) p]
gFromColumns ProtocolRevision
rev UVarInt
size = (f p -> D1 c (C1 c2 f) p) -> [f p] -> [D1 c (C1 c2 f) p]
forall a b. (a -> b) -> [a] -> [b]
map (C1 c2 f p -> D1 c (C1 c2 f) p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (C1 c2 f p -> D1 c (C1 c2 f) p)
-> (f p -> C1 c2 f p) -> f p -> D1 c (C1 c2 f) p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f p -> C1 c2 f p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1) ([f p] -> [D1 c (C1 c2 f) p])
-> Get [f p] -> Get [D1 c (C1 c2 f) p]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (columns :: [*]) (f :: * -> *) p.
GReadable columns f =>
ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @columns ProtocolRevision
rev UVarInt
size
  gReadingColumns :: Builder
gReadingColumns = forall (columns :: [*]) (f :: * -> *).
GReadable columns f =>
Builder
gReadingColumns @columns @f

instance
  GReadable columns (left :*: (right1 :*: right2))
  =>
  GReadable columns ((left :*: right1) :*: right2)
  where
  {-# INLINE gFromColumns #-}
  gFromColumns :: forall p.
ProtocolRevision
-> UVarInt -> Get [(:*:) (left :*: right1) right2 p]
gFromColumns ProtocolRevision
rev UVarInt
size = do
    [(:*:) left (right1 :*: right2) p]
list <- forall (columns :: [*]) (f :: * -> *) p.
GReadable columns f =>
ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @columns ProtocolRevision
rev UVarInt
size
    [(:*:) (left :*: right1) right2 p]
-> Get [(:*:) (left :*: right1) right2 p]
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(left p
l left p -> right1 p -> (:*:) left right1 p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: right1 p
r1) (:*:) left right1 p -> right2 p -> (:*:) (left :*: right1) right2 p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: right2 p
r2 | (left p
l :*: (right1 p
r1 :*: right2 p
r2)) <- [(:*:) left (right1 :*: right2) p]
list]
  gReadingColumns :: Builder
gReadingColumns = forall (columns :: [*]) (f :: * -> *).
GReadable columns f =>
Builder
gReadingColumns @columns @(left :*: (right1 :*: right2))


instance
  ( KnownColumn (Column name chType)
  , GReadable '[Column name chType] (S1 sel rec)
  , GReadable restColumns right
  )
  =>
  GReadable
    (Column name chType ': restColumns)
    (S1 sel rec :*: right)
  where
  {-# INLINE gFromColumns #-}
  gFromColumns :: forall p.
ProtocolRevision -> UVarInt -> Get [(:*:) (S1 sel rec) right p]
gFromColumns ProtocolRevision
rev UVarInt
size = do
    (S1 sel rec p -> right p -> (:*:) (S1 sel rec) right p)
-> [S1 sel rec p] -> [right p] -> [(:*:) (S1 sel rec) right p]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith S1 sel rec p -> right p -> (:*:) (S1 sel rec) right p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:)
      ([S1 sel rec p] -> [right p] -> [(:*:) (S1 sel rec) right p])
-> Get [S1 sel rec p]
-> Get ([right p] -> [(:*:) (S1 sel rec) right p])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (columns :: [*]) (f :: * -> *) p.
GReadable columns f =>
ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @'[Column name chType] ProtocolRevision
rev UVarInt
size
      Get ([right p] -> [(:*:) (S1 sel rec) right p])
-> Get [right p] -> Get [(:*:) (S1 sel rec) right p]
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (columns :: [*]) (f :: * -> *) p.
GReadable columns f =>
ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @restColumns ProtocolRevision
rev UVarInt
size
  gReadingColumns :: Builder
gReadingColumns =
    forall column. KnownColumn column => Builder
renderColumnName @(Column name chType)
    Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
", " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) (f :: * -> *).
GReadable columns f =>
Builder
gReadingColumns @restColumns @right

instance
  ( KnownColumn (Column name chType)
  , DeserializableColumn (Column name chType)
  , FromChType chType inputType
  , '(Column name chType, restColumns) ~ TakeColumn name columns
  ) => GReadable columns ((S1 (MetaSel (Just name) a b f)) (Rec0 inputType))
  where
  {-# INLINE gFromColumns #-}
  gFromColumns :: forall p.
ProtocolRevision
-> UVarInt
-> Get [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
gFromColumns ProtocolRevision
rev UVarInt
size = (chType -> S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p)
-> [chType]
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
forall a b. (a -> b) -> [a] -> [b]
map (Rec0 inputType p
-> S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (Rec0 inputType p
 -> S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p)
-> (chType -> Rec0 inputType p)
-> chType
-> S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. inputType -> Rec0 inputType p
forall k i c (p :: k). c -> K1 i c p
K1 (inputType -> Rec0 inputType p)
-> (chType -> inputType) -> chType -> Rec0 inputType p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType @chType) ([chType] -> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p])
-> (Column name chType -> [chType])
-> Column name chType
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Column name chType -> [chType]
forall (name :: Symbol) chType. Column name chType -> [chType]
columnValues (Column name chType
 -> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p])
-> Get (Column name chType)
-> Get [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall column.
DeserializableColumn column =>
ProtocolRevision -> UVarInt -> Get column
deserializeColumn @(Column name chType) ProtocolRevision
rev UVarInt
size
  gReadingColumns :: Builder
gReadingColumns = forall column. KnownColumn column => Builder
renderColumnName @(Column name chType)