{-# OPTIONS_GHC
-Wno-orphans
-Wno-unused-top-binds
-Wno-unused-imports
#-}
module ClickHaskell
(
ConnectionArgs, defaultConnectionArgs
, setHost, setPort, setUser, setDatabase, setPassword
, Connection(..), openConnection
, setSecure, overrideTLS
, ClientError(..)
, ConnectionError(..)
, UserError(..)
, InternalError(..)
, select, selectFrom, selectFromView, generateRandom
, ClickHaskell(..), FromChType(fromChType)
, insertInto
, ToChType(toChType)
, command, ping
, Column, KnownColumn, SerializableColumn
, Table, View
, ToQueryPart(toQueryPart), parameter, Parameter, Parameters, viewParameters
, IsChType(chTypeName, defaultValueOfTypeName)
, DateTime(..), DateTime64
, Int8, Int16, Int32, Int64, Int128(..)
, UInt8, UInt16, UInt32, UInt64, UInt128, Word128(..)
, Nullable
, LowCardinality, IsLowCardinalitySupported
, UUID(..)
, Array(..)
, ChString(..)
, UVarInt(..), SinceRevision(..), ProtocolRevision
, DataPacket(..), BlockInfo(..)
, ClientPacket(..)
, HelloPacket(..), Addendum(..)
, QueryPacket(..)
, DbSettings(..), QueryParameters(..), QueryStage(..)
, ClientInfo(..), QueryKind(..)
, ServerPacket(..)
, HelloResponse(..), PasswordComplexityRules(..)
, ExceptionPacket(..)
, ProgressPacket(..)
, ProfileInfo(..)
, TableColumns(..)
) where
import Paths_ClickHaskell (version)
import Control.Applicative (liftA2, liftA3)
import Control.Concurrent (MVar, newMVar, putMVar, takeMVar)
import Control.DeepSeq (NFData)
import Control.Exception (Exception, SomeException, bracketOnError, catch, finally, mask, onException, throw, throwIO)
import Control.Monad (forM, replicateM, void, when, (<$!>), (<=<))
import Data.Binary.Get
import Data.Binary.Get.Internal (readN)
import Data.Bits (Bits (setBit, unsafeShiftL, unsafeShiftR, (.&.), (.|.)))
import Data.ByteString as BS (ByteString, length, take)
import Data.ByteString.Builder
import Data.ByteString.Builder as BS (Builder, byteString)
import Data.ByteString.Char8 as BS8 (concatMap, length, pack, replicate, singleton)
import Data.ByteString.Lazy as BSL (toStrict, ByteString)
import Data.Coerce (coerce)
import Data.IORef (IORef, atomicModifyIORef, atomicWriteIORef, newIORef, readIORef)
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Kind (Constraint, Type)
import Data.List (uncons)
import Data.Maybe (listToMaybe, fromMaybe)
import Data.String (IsString (..))
import Data.Text (Text)
import Data.Text.Encoding as Text (encodeUtf8)
import Data.Time (UTCTime, ZonedTime, zonedTimeToUTC)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds)
import Data.Type.Bool (If)
import Data.Type.Equality (type (==))
import Data.Typeable (Proxy (..))
import Data.Version (Version (..))
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.Generics (C1, D1, Generic (..), K1 (K1, unK1), M1 (M1, unM1), Meta (MetaSel), Rec0, S1, type (:*:) (..))
import GHC.Stack (HasCallStack, callStack, prettyCallStack)
import GHC.TypeLits (AppendSymbol, ErrorMessage (..), KnownNat, KnownSymbol, Nat, Symbol, TypeError, natVal, symbolVal)
import System.Environment (lookupEnv)
import System.Timeout (timeout)
import Data.WideWord (Int128 (..), Word128(..))
import Network.Socket hiding (SocketOption(..))
import Network.Socket qualified as Sock (SocketOption(..))
import Network.Socket.ByteString (recv)
import Network.Socket.ByteString.Lazy (sendAll)
import Network.TLS (ClientParams (..), contextNew, contextClose, sendData, recvData, defaultParamsClient, handshake)
data ConnectionArgs = MkConnectionArgs
{ ConnectionArgs -> Text
user :: Text
, ConnectionArgs -> Text
pass :: Text
, ConnectionArgs -> Text
db :: Text
, ConnectionArgs -> String
host :: HostName
, ConnectionArgs -> Maybe String
mPort :: Maybe ServiceName
, ConnectionArgs -> Bool
isTLS :: Bool
, ConnectionArgs -> Maybe ClientParams
overriddenTLS :: Maybe ClientParams
, ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
initBuffer :: HostName -> SockAddr -> Socket -> IO Buffer
}
defaultConnectionArgs :: ConnectionArgs
defaultConnectionArgs :: ConnectionArgs
defaultConnectionArgs = MkConnectionArgs
{ user :: Text
user = Text
"default"
, pass :: Text
pass = Text
""
, host :: String
host = String
"localhost"
, db :: Text
db = Text
"default"
, isTLS :: Bool
isTLS = Bool
False
, mPort :: Maybe String
mPort = Maybe String
forall a. Maybe a
Nothing
, overriddenTLS :: Maybe ClientParams
overriddenTLS = Maybe ClientParams
forall a. Maybe a
Nothing
, initBuffer :: String -> SockAddr -> Socket -> IO Buffer
initBuffer = \String
_hostname SockAddr
addrAddress Socket
sock -> do
Socket -> SocketOption -> Int -> IO ()
setSocketOption Socket
sock SocketOption
Sock.NoDelay Int
1
Socket -> SocketOption -> Int -> IO ()
setSocketOption Socket
sock SocketOption
Sock.KeepAlive Int
1
Socket -> SockAddr -> IO ()
connect Socket
sock SockAddr
addrAddress
IORef ByteString
buff <- ByteString -> IO (IORef ByteString)
forall a. a -> IO (IORef a)
newIORef ByteString
""
Buffer -> IO Buffer
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
MkBuffer
{ writeSock :: ByteString -> IO ()
writeSock = \ByteString
bs -> Socket -> ByteString -> IO ()
sendAll Socket
sock ByteString
bs
, readSock :: IO ByteString
readSock = Socket -> Int -> IO ByteString
recv Socket
sock Int
4096
, closeSock :: IO ()
closeSock = Socket -> IO ()
close Socket
sock
, IORef ByteString
buff :: IORef ByteString
buff :: IORef ByteString
buff
}
}
overrideTLS :: ClientParams -> ConnectionArgs -> ConnectionArgs
overrideTLS :: ClientParams -> ConnectionArgs -> ConnectionArgs
overrideTLS ClientParams
clientParams MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} =
ConnectionArgs -> ConnectionArgs
setSecure (ConnectionArgs -> ConnectionArgs)
-> ConnectionArgs -> ConnectionArgs
forall a b. (a -> b) -> a -> b
$ MkConnectionArgs{overriddenTLS :: Maybe ClientParams
overriddenTLS = ClientParams -> Maybe ClientParams
forall a. a -> Maybe a
Just ClientParams
clientParams, Bool
String
Maybe String
Text
String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..}
setSecure :: ConnectionArgs -> ConnectionArgs
setSecure :: ConnectionArgs -> ConnectionArgs
setSecure MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} =
MkConnectionArgs{initBuffer :: String -> SockAddr -> Socket -> IO Buffer
initBuffer = String -> SockAddr -> Socket -> IO Buffer
initTLS, isTLS :: Bool
isTLS=Bool
True, String
Maybe String
Maybe ClientParams
Text
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
overriddenTLS :: Maybe ClientParams
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
overriddenTLS :: Maybe ClientParams
..}
where
initTLS :: String -> SockAddr -> Socket -> IO Buffer
initTLS = \String
hostname SockAddr
addrAddress Socket
sock -> do
Socket -> SocketOption -> Int -> IO ()
setSocketOption Socket
sock SocketOption
Sock.NoDelay Int
1
Socket -> SocketOption -> Int -> IO ()
setSocketOption Socket
sock SocketOption
Sock.KeepAlive Int
1
Socket -> SockAddr -> IO ()
connect Socket
sock SockAddr
addrAddress
let defClientParams :: ClientParams
defClientParams = (String -> ByteString -> ClientParams
defaultParamsClient String
hostname ByteString
"")
Context
context <- Socket -> ClientParams -> IO Context
forall (m :: * -> *) backend params.
(MonadIO m, HasBackend backend, TLSParams params) =>
backend -> params -> m Context
contextNew Socket
sock (ClientParams -> Maybe ClientParams -> ClientParams
forall a. a -> Maybe a -> a
fromMaybe ClientParams
defClientParams Maybe ClientParams
overriddenTLS)
Context -> IO ()
forall (m :: * -> *). MonadIO m => Context -> m ()
handshake Context
context
IORef ByteString
buff <- ByteString -> IO (IORef ByteString)
forall a. a -> IO (IORef a)
newIORef ByteString
""
Buffer -> IO Buffer
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
MkBuffer
{ writeSock :: ByteString -> IO ()
writeSock = \ByteString
bs -> Context -> ByteString -> IO ()
forall (m :: * -> *). MonadIO m => Context -> ByteString -> m ()
sendData Context
context ByteString
bs
, readSock :: IO ByteString
readSock = Context -> IO ByteString
forall (m :: * -> *). MonadIO m => Context -> m ByteString
recvData Context
context
, closeSock :: IO ()
closeSock = Context -> IO ()
contextClose Context
context
, IORef ByteString
buff :: IORef ByteString
buff :: IORef ByteString
buff
}
setUser :: Text -> ConnectionArgs -> ConnectionArgs
setUser :: Text -> ConnectionArgs -> ConnectionArgs
setUser Text
new MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} = MkConnectionArgs{user :: Text
user=Text
new, Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..}
setPassword :: Text -> ConnectionArgs -> ConnectionArgs
setPassword :: Text -> ConnectionArgs -> ConnectionArgs
setPassword Text
new MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} = MkConnectionArgs{pass :: Text
pass=Text
new, Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
user :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..}
setHost :: HostName -> ConnectionArgs -> ConnectionArgs
setHost :: String -> ConnectionArgs -> ConnectionArgs
setHost String
new MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} = MkConnectionArgs{host :: String
host=String
new, Bool
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..}
setPort :: ServiceName -> ConnectionArgs -> ConnectionArgs
setPort :: String -> ConnectionArgs -> ConnectionArgs
setPort String
new MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} = MkConnectionArgs{mPort :: Maybe String
mPort=String -> Maybe String
forall a. a -> Maybe a
Just String
new, Bool
String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..}
setDatabase :: Text -> ConnectionArgs -> ConnectionArgs
setDatabase :: Text -> ConnectionArgs -> ConnectionArgs
setDatabase Text
new MkConnectionArgs{Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: ConnectionArgs -> Text
pass :: ConnectionArgs -> Text
db :: ConnectionArgs -> Text
host :: ConnectionArgs -> String
mPort :: ConnectionArgs -> Maybe String
isTLS :: ConnectionArgs -> Bool
overriddenTLS :: ConnectionArgs -> Maybe ClientParams
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
db :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..} = MkConnectionArgs{db :: Text
db=Text
new, Bool
String
Maybe String
Maybe ClientParams
Text
String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
user :: Text
pass :: Text
host :: String
mPort :: Maybe String
isTLS :: Bool
overriddenTLS :: Maybe ClientParams
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
..}
data Connection where MkConnection :: (MVar ConnectionState) -> Connection
withConnection :: HasCallStack => Connection -> (ConnectionState -> IO a) -> IO a
withConnection :: forall a.
HasCallStack =>
Connection -> (ConnectionState -> IO a) -> IO a
withConnection (MkConnection MVar ConnectionState
connStateMVar) ConnectionState -> IO a
f =
((forall a. IO a -> IO a) -> IO a) -> IO a
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
mask (((forall a. IO a -> IO a) -> IO a) -> IO a)
-> ((forall a. IO a -> IO a) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
ConnectionState
connState <- MVar ConnectionState -> IO ConnectionState
forall a. MVar a -> IO a
takeMVar MVar ConnectionState
connStateMVar
a
b <- IO a -> IO () -> IO a
forall a b. IO a -> IO b -> IO a
onException
(IO a -> IO a
forall a. IO a -> IO a
restore (ConnectionState -> IO a
f ConnectionState
connState))
(MVar ConnectionState -> ConnectionState -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar ConnectionState
connStateMVar (ConnectionState -> IO ()) -> IO ConnectionState -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ConnectionState -> IO ConnectionState
reopenConnection ConnectionState
connState)
MVar ConnectionState -> ConnectionState -> IO ()
forall a. MVar a -> a -> IO ()
putMVar MVar ConnectionState
connStateMVar ConnectionState
connState
a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
b
data ConnectionState = MkConnectionState
{ ConnectionState -> ChString
user :: ChString
, ConnectionState -> ChString
hostname :: ChString
, ConnectionState -> ChString
os_user :: ChString
, ConnectionState -> Buffer
buffer :: Buffer
, ConnectionState -> ProtocolRevision
revision :: ProtocolRevision
, ConnectionState -> ConnectionArgs
creds :: ConnectionArgs
}
writeToConnection :: Serializable packet => ConnectionState -> packet -> IO ()
writeToConnection :: forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection MkConnectionState{ProtocolRevision
revision :: ConnectionState -> ProtocolRevision
revision :: ProtocolRevision
revision, Buffer
buffer :: ConnectionState -> Buffer
buffer :: Buffer
buffer} packet
packet =
(Buffer -> ByteString -> IO ()
writeSock Buffer
buffer (ByteString -> IO ()) -> (packet -> ByteString) -> packet -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
toLazyByteString (Builder -> ByteString)
-> (packet -> Builder) -> packet -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtocolRevision -> packet -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
revision) packet
packet
writeToConnectionEncode :: ConnectionState -> (ProtocolRevision -> Builder) -> IO ()
writeToConnectionEncode :: ConnectionState -> (ProtocolRevision -> Builder) -> IO ()
writeToConnectionEncode MkConnectionState{ProtocolRevision
revision :: ConnectionState -> ProtocolRevision
revision :: ProtocolRevision
revision, Buffer
buffer :: ConnectionState -> Buffer
buffer :: Buffer
buffer} ProtocolRevision -> Builder
serializer =
(Buffer -> ByteString -> IO ()
writeSock Buffer
buffer (ByteString -> IO ())
-> (Builder -> ByteString) -> Builder -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
toLazyByteString) (ProtocolRevision -> Builder
serializer ProtocolRevision
revision)
openConnection :: HasCallStack => ConnectionArgs -> IO Connection
openConnection :: HasCallStack => ConnectionArgs -> IO Connection
openConnection ConnectionArgs
creds = (MVar ConnectionState -> Connection)
-> IO (MVar ConnectionState) -> IO Connection
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MVar ConnectionState -> Connection
MkConnection (IO (MVar ConnectionState) -> IO Connection)
-> (ConnectionState -> IO (MVar ConnectionState))
-> ConnectionState
-> IO Connection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConnectionState -> IO (MVar ConnectionState)
forall a. a -> IO (MVar a)
newMVar (ConnectionState -> IO Connection)
-> IO ConnectionState -> IO Connection
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ConnectionArgs -> IO ConnectionState
createConnectionState ConnectionArgs
creds
reopenConnection :: ConnectionState -> IO ConnectionState
reopenConnection :: ConnectionState -> IO ConnectionState
reopenConnection MkConnectionState{ConnectionArgs
creds :: ConnectionState -> ConnectionArgs
creds :: ConnectionArgs
creds, Buffer
buffer :: ConnectionState -> Buffer
buffer :: Buffer
buffer} = do
Buffer -> IO ()
flushBuffer Buffer
buffer
Buffer -> IO ()
closeSock Buffer
buffer
ConnectionArgs -> IO ConnectionState
createConnectionState ConnectionArgs
creds
createConnectionState :: ConnectionArgs -> IO ConnectionState
createConnectionState :: ConnectionArgs -> IO ConnectionState
createConnectionState creds :: ConnectionArgs
creds@MkConnectionArgs {Text
user :: ConnectionArgs -> Text
user :: Text
user, Text
pass :: ConnectionArgs -> Text
pass :: Text
pass, Text
db :: ConnectionArgs -> Text
db :: Text
db, String
host :: ConnectionArgs -> String
host :: String
host, Maybe String
mPort :: ConnectionArgs -> Maybe String
mPort :: Maybe String
mPort, String -> SockAddr -> Socket -> IO Buffer
initBuffer :: ConnectionArgs -> String -> SockAddr -> Socket -> IO Buffer
initBuffer :: String -> SockAddr -> Socket -> IO Buffer
initBuffer, Bool
isTLS :: ConnectionArgs -> Bool
isTLS :: Bool
isTLS} = do
let port :: String
port = String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe (if Bool
isTLS then String
"9440" else String
"9000") Maybe String
mPort
ChString
hostname <- ChString -> (String -> ChString) -> Maybe String -> ChString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ChString
"" String -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Maybe String -> ChString) -> IO (Maybe String) -> IO ChString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> IO (Maybe String)
lookupEnv String
"HOSTNAME"
ChString
os_user <- ChString -> (String -> ChString) -> Maybe String -> ChString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ChString
"" String -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Maybe String -> ChString) -> IO (Maybe String) -> IO ChString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> IO (Maybe String)
lookupEnv String
"USER"
AddrInfo{Family
addrFamily :: Family
addrFamily :: AddrInfo -> Family
addrFamily, SocketType
addrSocketType :: SocketType
addrSocketType :: AddrInfo -> SocketType
addrSocketType, ProtocolNumber
addrProtocol :: ProtocolNumber
addrProtocol :: AddrInfo -> ProtocolNumber
addrProtocol, SockAddr
addrAddress :: SockAddr
addrAddress :: AddrInfo -> SockAddr
addrAddress}
<- IO AddrInfo
-> (AddrInfo -> IO AddrInfo) -> Maybe AddrInfo -> IO AddrInfo
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ConnectionError -> IO AddrInfo
forall e a. Exception e => e -> IO a
throwIO ConnectionError
NoAdressResolved) AddrInfo -> IO AddrInfo
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe AddrInfo -> IO AddrInfo)
-> ([AddrInfo] -> Maybe AddrInfo) -> [AddrInfo] -> IO AddrInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [AddrInfo] -> Maybe AddrInfo
forall a. [a] -> Maybe a
listToMaybe
([AddrInfo] -> IO AddrInfo) -> IO [AddrInfo] -> IO AddrInfo
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe AddrInfo -> Maybe String -> Maybe String -> IO [AddrInfo]
forall (t :: * -> *).
GetAddrInfo t =>
Maybe AddrInfo -> Maybe String -> Maybe String -> IO (t AddrInfo)
getAddrInfo
(AddrInfo -> Maybe AddrInfo
forall a. a -> Maybe a
Just AddrInfo
defaultHints{addrFlags = [AI_ADDRCONFIG], addrSocketType = Stream})
(String -> Maybe String
forall a. a -> Maybe a
Just String
host)
(String -> Maybe String
forall a. a -> Maybe a
Just String
port)
Buffer
buffer <- IO Buffer -> (Buffer -> IO Buffer) -> Maybe Buffer -> IO Buffer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ConnectionError -> IO Buffer
forall e a. Exception e => e -> IO a
throwIO ConnectionError
EstablishTimeout) Buffer -> IO Buffer
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(Maybe Buffer -> IO Buffer) -> IO (Maybe Buffer) -> IO Buffer
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> IO Buffer -> IO (Maybe Buffer)
forall a. Int -> IO a -> IO (Maybe a)
timeout Int
3_000_000 (
IO Socket
-> (Socket -> IO ()) -> (Socket -> IO Buffer) -> IO Buffer
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracketOnError
(Family -> SocketType -> ProtocolNumber -> IO Socket
socket Family
addrFamily SocketType
addrSocketType ProtocolNumber
addrProtocol)
(\Socket
sock ->
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch @SomeException
(IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
finally (Socket -> ShutdownCmd -> IO ()
shutdown Socket
sock ShutdownCmd
ShutdownBoth) (Socket -> IO ()
close Socket
sock))
(IO () -> SomeException -> IO ()
forall a b. a -> b -> a
const (IO () -> SomeException -> IO ())
-> IO () -> SomeException -> IO ()
forall a b. (a -> b) -> a -> b
$ () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
)
(\Socket
sock -> String -> SockAddr -> Socket -> IO Buffer
initBuffer String
host SockAddr
addrAddress Socket
sock)
)
(Buffer -> ByteString -> IO ()
writeSock Buffer
buffer (ByteString -> IO ())
-> (ClientPacket -> ByteString) -> ClientPacket -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
toLazyByteString (Builder -> ByteString)
-> (ClientPacket -> Builder) -> ClientPacket -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtocolRevision -> ClientPacket -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
latestSupportedRevision)
(Text -> Text -> Text -> ClientPacket
mkHelloPacket Text
db Text
user Text
pass)
ServerPacket
serverPacketType <- Buffer -> Get ServerPacket -> IO ServerPacket
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (ProtocolRevision -> Get ServerPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
latestSupportedRevision)
case ServerPacket
serverPacketType of
HelloResponse MkHelloResponse{ProtocolRevision
server_revision :: ProtocolRevision
server_revision :: HelloResponse -> ProtocolRevision
server_revision} -> do
let revision :: ProtocolRevision
revision = ProtocolRevision -> ProtocolRevision -> ProtocolRevision
forall a. Ord a => a -> a -> a
min ProtocolRevision
server_revision ProtocolRevision
latestSupportedRevision
conn :: ConnectionState
conn = MkConnectionState{user :: ChString
user = Text -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType Text
user, ProtocolRevision
ChString
Buffer
ConnectionArgs
hostname :: ChString
os_user :: ChString
buffer :: Buffer
revision :: ProtocolRevision
creds :: ConnectionArgs
creds :: ConnectionArgs
hostname :: ChString
os_user :: ChString
buffer :: Buffer
revision :: ProtocolRevision
..}
ConnectionState -> Addendum -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
conn MkAddendum{quota_key :: SinceRevision ChString DBMS_MIN_PROTOCOL_VERSION_WITH_QUOTA_KEY
quota_key = ChString
-> SinceRevision ChString DBMS_MIN_PROTOCOL_VERSION_WITH_QUOTA_KEY
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision ChString
""}
ConnectionState -> IO ConnectionState
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConnectionState
conn
Exception ExceptionPacket
exception -> ClientError -> IO ConnectionState
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError) -> UserError -> ClientError
forall a b. (a -> b) -> a -> b
$ ExceptionPacket -> UserError
DatabaseException ExceptionPacket
exception)
ServerPacket
otherPacket -> ClientError -> IO ConnectionState
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => InternalError -> ClientError
InternalError -> ClientError
InternalError (InternalError -> ClientError) -> InternalError -> ClientError
forall a b. (a -> b) -> a -> b
$ UVarInt -> InternalError
UnexpectedPacketType (UVarInt -> InternalError) -> UVarInt -> InternalError
forall a b. (a -> b) -> a -> b
$ ServerPacket -> UVarInt
serverPacketToNum ServerPacket
otherPacket)
command :: HasCallStack => Connection -> ChString -> IO ()
command :: HasCallStack => Connection -> ChString -> IO ()
command Connection
conn ChString
query = do
Connection -> (ConnectionState -> IO ()) -> IO ()
forall a.
HasCallStack =>
Connection -> (ConnectionState -> IO a) -> IO a
withConnection Connection
conn ((ConnectionState -> IO ()) -> IO ())
-> (ConnectionState -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ConnectionState
connState -> do
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState (ConnectionState -> ChString -> ClientPacket
mkQueryPacket ConnectionState
connState ChString
query)
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState (ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket ChString
"" UVarInt
0 UVarInt
0)
ConnectionState -> IO ()
handleCreate ConnectionState
connState
where
handleCreate :: ConnectionState -> IO ()
handleCreate :: ConnectionState -> IO ()
handleCreate MkConnectionState{ProtocolRevision
ChString
Buffer
ConnectionArgs
user :: ConnectionState -> ChString
hostname :: ConnectionState -> ChString
os_user :: ConnectionState -> ChString
buffer :: ConnectionState -> Buffer
revision :: ConnectionState -> ProtocolRevision
creds :: ConnectionState -> ConnectionArgs
user :: ChString
hostname :: ChString
os_user :: ChString
buffer :: Buffer
revision :: ProtocolRevision
creds :: ConnectionArgs
..} =
Buffer -> Get ServerPacket -> IO ServerPacket
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (ProtocolRevision -> Get ServerPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
revision)
IO ServerPacket -> (ServerPacket -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ServerPacket
packet -> case ServerPacket
packet of
ServerPacket
EndOfStream -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Exception ExceptionPacket
exception -> ClientError -> IO ()
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError) -> UserError -> ClientError
forall a b. (a -> b) -> a -> b
$ ExceptionPacket -> UserError
DatabaseException ExceptionPacket
exception)
ServerPacket
otherPacket -> ClientError -> IO ()
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => InternalError -> ClientError
InternalError -> ClientError
InternalError (InternalError -> ClientError) -> InternalError -> ClientError
forall a b. (a -> b) -> a -> b
$ UVarInt -> InternalError
UnexpectedPacketType (UVarInt -> InternalError) -> UVarInt -> InternalError
forall a b. (a -> b) -> a -> b
$ ServerPacket -> UVarInt
serverPacketToNum ServerPacket
otherPacket)
ping :: HasCallStack => Connection -> IO ()
ping :: HasCallStack => Connection -> IO ()
ping Connection
conn = do
Connection -> (ConnectionState -> IO ()) -> IO ()
forall a.
HasCallStack =>
Connection -> (ConnectionState -> IO a) -> IO a
withConnection Connection
conn ((ConnectionState -> IO ()) -> IO ())
-> (ConnectionState -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \connState :: ConnectionState
connState@MkConnectionState{ProtocolRevision
revision :: ConnectionState -> ProtocolRevision
revision :: ProtocolRevision
revision, Buffer
buffer :: ConnectionState -> Buffer
buffer :: Buffer
buffer} -> do
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState ClientPacket
Ping
ServerPacket
responsePacket <- Buffer -> Get ServerPacket -> IO ServerPacket
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (ProtocolRevision -> Get ServerPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
revision)
case ServerPacket
responsePacket of
ServerPacket
Pong -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Exception ExceptionPacket
exception -> ClientError -> IO ()
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError) -> UserError -> ClientError
forall a b. (a -> b) -> a -> b
$ ExceptionPacket -> UserError
DatabaseException ExceptionPacket
exception)
ServerPacket
otherPacket -> ClientError -> IO ()
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => InternalError -> ClientError
InternalError -> ClientError
InternalError (InternalError -> ClientError) -> InternalError -> ClientError
forall a b. (a -> b) -> a -> b
$ UVarInt -> InternalError
UnexpectedPacketType (UVarInt -> InternalError) -> UVarInt -> InternalError
forall a b. (a -> b) -> a -> b
$ ServerPacket -> UVarInt
serverPacketToNum ServerPacket
otherPacket)
class IsTable table where
type GetColumns table :: [Type]
tableName :: Builder
class HasParameters view where
type GetParams view :: [Type]
select ::
forall columns output result
.
ClickHaskell columns output
=>
Connection -> ChString -> ([output] -> IO result) -> IO [result]
select :: forall (columns :: [*]) output result.
ClickHaskell columns output =>
Connection -> ChString -> ([output] -> IO result) -> IO [result]
select Connection
conn ChString
query [output] -> IO result
f = do
Connection -> (ConnectionState -> IO [result]) -> IO [result]
forall a.
HasCallStack =>
Connection -> (ConnectionState -> IO a) -> IO a
withConnection Connection
conn ((ConnectionState -> IO [result]) -> IO [result])
-> (ConnectionState -> IO [result]) -> IO [result]
forall a b. (a -> b) -> a -> b
$ \ConnectionState
connState -> do
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState (ConnectionState -> ChString -> ClientPacket
mkQueryPacket ConnectionState
connState ChString
query)
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState (ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket ChString
"" UVarInt
0 UVarInt
0)
forall (columns :: [*]) output result.
ClickHaskell columns output =>
ConnectionState -> ([output] -> IO result) -> IO [result]
handleSelect @columns ConnectionState
connState (\[output]
x -> result -> result
forall a. a -> a
id (result -> result) -> IO result -> IO result
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> [output] -> IO result
f [output]
x)
data Table (name :: Symbol) (columns :: [Type])
instance KnownSymbol name => IsTable (Table name columns) where
type GetColumns (Table name columns) = columns
tableName :: Builder
tableName = (ByteString -> Builder
byteString (ByteString -> Builder)
-> (String -> ByteString) -> String -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack) (Proxy name -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (Proxy name -> String) -> Proxy name -> String
forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @name)
type ClickHaskellTable table record =
( IsTable table
, ClickHaskell (GetColumns table) record
)
selectFrom ::
forall table output result
.
ClickHaskellTable table output
=>
Connection -> ([output] -> IO result) -> IO [result]
selectFrom :: forall table output result.
ClickHaskellTable table output =>
Connection -> ([output] -> IO result) -> IO [result]
selectFrom Connection
conn [output] -> IO result
f = forall (columns :: [*]) output result.
ClickHaskell columns output =>
Connection -> ChString -> ([output] -> IO result) -> IO [result]
select @(GetColumns table) Connection
conn ChString
query [output] -> IO result
f
where
query :: ChString
query = Builder -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$
Builder
"SELECT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) record.
ClickHaskell columns record =>
Builder
columns @(GetColumns table) @output Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
" FROM " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall table. IsTable table => Builder
tableName @table
data View (name :: Symbol) (columns :: [Type]) (parameters :: [Type])
selectFromView ::
forall view output result name columns parameters passedParameters
.
( ClickHaskell columns output
, KnownSymbol name
, view ~ View name columns parameters
)
=> Connection -> (Parameters '[] -> Parameters passedParameters) -> ([output] -> IO result) -> IO [result]
selectFromView :: forall view output result (name :: Symbol) (columns :: [*])
(parameters :: [*]) (passedParameters :: [*]).
(ClickHaskell columns output, KnownSymbol name,
view ~ View name columns parameters) =>
Connection
-> (Parameters '[] -> Parameters passedParameters)
-> ([output] -> IO result)
-> IO [result]
selectFromView Connection
conn Parameters '[] -> Parameters passedParameters
interpreter [output] -> IO result
f = forall (columns :: [*]) output result.
ClickHaskell columns output =>
Connection -> ChString -> ([output] -> IO result) -> IO [result]
select @columns Connection
conn ChString
query [output] -> IO result
f
where
query :: ChString
query = Builder -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$
Builder
"SELECT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) record.
ClickHaskell columns record =>
Builder
columns @columns @output Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
" FROM " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (ByteString -> Builder
byteString (ByteString -> Builder)
-> (Proxy name -> ByteString) -> Proxy name -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (Proxy name -> String) -> Proxy name -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @name) Proxy name
forall {k} (t :: k). Proxy t
Proxy Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (Parameters '[] -> Parameters passedParameters) -> Builder
forall (passedParameters :: [*]).
(Parameters '[] -> Parameters passedParameters) -> Builder
viewParameters Parameters '[] -> Parameters passedParameters
interpreter
generateRandom ::
forall columns output result
.
ClickHaskell columns output
=>
Connection -> (UInt64, UInt64, UInt64) -> UInt64 -> ([output] -> IO result) -> IO [result]
generateRandom :: forall (columns :: [*]) output result.
ClickHaskell columns output =>
Connection
-> (UInt64, UInt64, UInt64)
-> UInt64
-> ([output] -> IO result)
-> IO [result]
generateRandom Connection
conn (UInt64
randomSeed, UInt64
maxStrLen, UInt64
maxArrayLen) UInt64
limit [output] -> IO result
f = forall (columns :: [*]) output result.
ClickHaskell columns output =>
Connection -> ChString -> ([output] -> IO result) -> IO [result]
select @columns Connection
conn ChString
query [output] -> IO result
f
where
query :: ChString
query = Builder -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$
Builder
"SELECT * FROM generateRandom(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
"'" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) record.
ClickHaskell columns record =>
Builder
readingColumnsAndTypes @columns @output Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"' ," Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
UInt64 -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart UInt64
randomSeed Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"," Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
UInt64 -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart UInt64
maxStrLen Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"," Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
UInt64 -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart UInt64
maxArrayLen Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
")" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
Builder
" LIMIT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> UInt64 -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart UInt64
limit Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
";"
handleSelect ::
forall columns output result
.
ClickHaskell columns output
=>
ConnectionState -> ([output] -> IO result) -> IO [result]
handleSelect :: forall (columns :: [*]) output result.
ClickHaskell columns output =>
ConnectionState -> ([output] -> IO result) -> IO [result]
handleSelect MkConnectionState{ProtocolRevision
ChString
Buffer
ConnectionArgs
user :: ConnectionState -> ChString
hostname :: ConnectionState -> ChString
os_user :: ConnectionState -> ChString
buffer :: ConnectionState -> Buffer
revision :: ConnectionState -> ProtocolRevision
creds :: ConnectionState -> ConnectionArgs
user :: ChString
hostname :: ChString
os_user :: ChString
buffer :: Buffer
revision :: ProtocolRevision
creds :: ConnectionArgs
..} [output] -> IO result
f = [result] -> IO [result]
loop []
where
loop :: [result] -> IO [result]
loop [result]
acc = Buffer -> Get ServerPacket -> IO ServerPacket
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (ProtocolRevision -> Get ServerPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
revision) IO ServerPacket -> (ServerPacket -> IO [result]) -> IO [result]
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
\ServerPacket
packet -> case ServerPacket
packet of
DataResponse MkDataPacket{columns_count :: DataPacket -> UVarInt
columns_count = UVarInt
0, rows_count :: DataPacket -> UVarInt
rows_count = UVarInt
0} -> [result] -> IO [result]
loop [result]
acc
DataResponse MkDataPacket{UVarInt
columns_count :: DataPacket -> UVarInt
columns_count :: UVarInt
columns_count, UVarInt
rows_count :: DataPacket -> UVarInt
rows_count :: UVarInt
rows_count} -> do
let expected :: UVarInt
expected = forall (columns :: [*]) record.
ClickHaskell columns record =>
UVarInt
columnsCount @columns @output
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (UVarInt
columns_count UVarInt -> UVarInt -> Bool
forall a. Eq a => a -> a -> Bool
/= UVarInt
expected) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
(ClientError -> IO ()
forall a e. Exception e => e -> a
throw (ClientError -> IO ())
-> (String -> ClientError) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError)
-> (String -> UserError) -> String -> ClientError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> UserError
UnmatchedColumnsCount)
(String
"Expected " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UVarInt -> String
forall a. Show a => a -> String
show UVarInt
expected String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" columns but got " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UVarInt -> String
forall a. Show a => a -> String
show UVarInt
columns_count)
result
result <- [output] -> IO result
f ([output] -> IO result) -> IO [output] -> IO result
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Buffer -> Get [output] -> IO [output]
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (forall (columns :: [*]) record.
ClickHaskell columns record =>
Bool -> ProtocolRevision -> UVarInt -> Get [record]
deserializeColumns @columns Bool
True ProtocolRevision
revision UVarInt
rows_count)
[result] -> IO [result]
loop (result
result result -> [result] -> [result]
forall a. a -> [a] -> [a]
: [result]
acc)
Progress ProgressPacket
_ -> [result] -> IO [result]
loop [result]
acc
ProfileInfo ProfileInfo
_ -> [result] -> IO [result]
loop [result]
acc
ServerPacket
EndOfStream -> [result] -> IO [result]
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [result]
acc
Exception ExceptionPacket
exception -> ClientError -> IO [result]
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError) -> UserError -> ClientError
forall a b. (a -> b) -> a -> b
$ ExceptionPacket -> UserError
DatabaseException ExceptionPacket
exception)
ServerPacket
otherPacket -> ClientError -> IO [result]
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => InternalError -> ClientError
InternalError -> ClientError
InternalError (InternalError -> ClientError) -> InternalError -> ClientError
forall a b. (a -> b) -> a -> b
$ UVarInt -> InternalError
UnexpectedPacketType (UVarInt -> InternalError) -> UVarInt -> InternalError
forall a b. (a -> b) -> a -> b
$ ServerPacket -> UVarInt
serverPacketToNum ServerPacket
otherPacket)
insertInto ::
forall table record name columns
.
( table ~ Table name columns
, ClickHaskell columns record
, KnownSymbol name
)
=> Connection -> [record] -> IO ()
insertInto :: forall table record (name :: Symbol) (columns :: [*]).
(table ~ Table name columns, ClickHaskell columns record,
KnownSymbol name) =>
Connection -> [record] -> IO ()
insertInto Connection
conn [record]
columnsData = do
Connection -> (ConnectionState -> IO ()) -> IO ()
forall a.
HasCallStack =>
Connection -> (ConnectionState -> IO a) -> IO a
withConnection Connection
conn ((ConnectionState -> IO ()) -> IO ())
-> (ConnectionState -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ConnectionState
connState -> do
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState (ConnectionState -> ChString -> ClientPacket
mkQueryPacket ConnectionState
connState ChString
query)
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
connState (ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket ChString
"" UVarInt
0 UVarInt
0)
forall (columns :: [*]) record.
ClickHaskell columns record =>
ConnectionState -> [record] -> IO ()
handleInsertResult @columns ConnectionState
connState [record]
columnsData
where
query :: ChString
query = Builder -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$
Builder
"INSERT INTO " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (ByteString -> Builder
byteString (ByteString -> Builder)
-> (Proxy name -> ByteString) -> Proxy name -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (Proxy name -> String) -> Proxy name -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @name (Proxy name -> Builder) -> Proxy name -> Builder
forall a b. (a -> b) -> a -> b
$ Proxy name
forall {k} (t :: k). Proxy t
Proxy)
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) record.
ClickHaskell columns record =>
Builder
columns @columns @record Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
") VALUES"
handleInsertResult :: forall columns record . ClickHaskell columns record => ConnectionState -> [record] -> IO ()
handleInsertResult :: forall (columns :: [*]) record.
ClickHaskell columns record =>
ConnectionState -> [record] -> IO ()
handleInsertResult conn :: ConnectionState
conn@MkConnectionState{ProtocolRevision
ChString
Buffer
ConnectionArgs
user :: ConnectionState -> ChString
hostname :: ConnectionState -> ChString
os_user :: ConnectionState -> ChString
buffer :: ConnectionState -> Buffer
revision :: ConnectionState -> ProtocolRevision
creds :: ConnectionState -> ConnectionArgs
user :: ChString
hostname :: ChString
os_user :: ChString
buffer :: Buffer
revision :: ProtocolRevision
creds :: ConnectionArgs
..} [record]
records = do
ServerPacket
firstPacket <- Buffer -> Get ServerPacket -> IO ServerPacket
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (ProtocolRevision -> Get ServerPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
revision)
case ServerPacket
firstPacket of
TableColumns TableColumns
_ -> forall (columns :: [*]) record.
ClickHaskell columns record =>
ConnectionState -> [record] -> IO ()
handleInsertResult @columns ConnectionState
conn [record]
records
DataResponse MkDataPacket{} -> do
[record]
_emptyDataPacket <- Buffer -> Get [record] -> IO [record]
forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead Buffer
buffer (forall (columns :: [*]) record.
ClickHaskell columns record =>
Bool -> ProtocolRevision -> UVarInt -> Get [record]
deserializeColumns @columns @record Bool
False ProtocolRevision
revision UVarInt
0)
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
conn (ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket ChString
"" (forall (columns :: [*]) record.
ClickHaskell columns record =>
UVarInt
columnsCount @columns @record) (Int -> UVarInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> UVarInt) -> Int -> UVarInt
forall a b. (a -> b) -> a -> b
$ [record] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [record]
records))
ConnectionState -> (ProtocolRevision -> Builder) -> IO ()
writeToConnectionEncode ConnectionState
conn (forall (columns :: [*]) record.
ClickHaskell columns record =>
[record] -> ProtocolRevision -> Builder
serializeRecords @columns [record]
records)
ConnectionState -> ClientPacket -> IO ()
forall packet.
Serializable packet =>
ConnectionState -> packet -> IO ()
writeToConnection ConnectionState
conn (ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket ChString
"" UVarInt
0 UVarInt
0)
forall (columns :: [*]) record.
ClickHaskell columns record =>
ConnectionState -> [record] -> IO ()
handleInsertResult @columns @record ConnectionState
conn []
ServerPacket
EndOfStream -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Exception ExceptionPacket
exception -> ClientError -> IO ()
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError) -> UserError -> ClientError
forall a b. (a -> b) -> a -> b
$ ExceptionPacket -> UserError
DatabaseException ExceptionPacket
exception)
ServerPacket
otherPacket -> ClientError -> IO ()
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => InternalError -> ClientError
InternalError -> ClientError
InternalError (InternalError -> ClientError) -> InternalError -> ClientError
forall a b. (a -> b) -> a -> b
$ UVarInt -> InternalError
UnexpectedPacketType (UVarInt -> InternalError) -> UVarInt -> InternalError
forall a b. (a -> b) -> a -> b
$ ServerPacket -> UVarInt
serverPacketToNum ServerPacket
otherPacket)
data Buffer = MkBuffer
{ Buffer -> IO ByteString
readSock :: IO BS.ByteString
, Buffer -> ByteString -> IO ()
writeSock :: BSL.ByteString -> IO ()
, Buffer -> IO ()
closeSock :: IO ()
, Buffer -> IORef ByteString
buff :: IORef BS.ByteString
}
flushBuffer :: Buffer -> IO ()
flushBuffer :: Buffer -> IO ()
flushBuffer MkBuffer{IORef ByteString
buff :: Buffer -> IORef ByteString
buff :: IORef ByteString
buff} = IORef ByteString -> ByteString -> IO ()
forall a. IORef a -> a -> IO ()
atomicWriteIORef IORef ByteString
buff ByteString
""
rawBufferizedRead :: Buffer -> Get packet -> IO packet
rawBufferizedRead :: forall packet. Buffer -> Get packet -> IO packet
rawBufferizedRead buffer :: Buffer
buffer@MkBuffer{IO ()
IO ByteString
IORef ByteString
ByteString -> IO ()
writeSock :: Buffer -> ByteString -> IO ()
readSock :: Buffer -> IO ByteString
closeSock :: Buffer -> IO ()
buff :: Buffer -> IORef ByteString
readSock :: IO ByteString
writeSock :: ByteString -> IO ()
closeSock :: IO ()
buff :: IORef ByteString
..} Get packet
parser = Decoder packet -> IO packet
forall packet. Decoder packet -> IO packet
runBufferReader (Get packet -> Decoder packet
forall a. Get a -> Decoder a
runGetIncremental Get packet
parser)
where
runBufferReader :: Decoder packet -> IO packet
runBufferReader :: forall packet. Decoder packet -> IO packet
runBufferReader = \case
(Partial Maybe ByteString -> Decoder packet
decoder) -> IO ByteString
readBuffer IO ByteString -> (ByteString -> IO packet) -> IO packet
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Decoder packet -> IO packet
forall packet. Decoder packet -> IO packet
runBufferReader (Decoder packet -> IO packet)
-> (ByteString -> Decoder packet) -> ByteString -> IO packet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe ByteString -> Decoder packet
decoder (Maybe ByteString -> Decoder packet)
-> (ByteString -> Maybe ByteString) -> ByteString -> Decoder packet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just
(Done ByteString
leftover Int64
_consumed packet
packet) -> packet
packet packet -> IO ByteString -> IO packet
forall a b. a -> IO b -> IO a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ IORef ByteString
-> (ByteString -> (ByteString, ByteString)) -> IO ByteString
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef IORef ByteString
buff (ByteString
leftover,)
(Fail ByteString
_leftover Int64
_consumed String
msg) -> ClientError -> IO packet
forall e a. Exception e => e -> IO a
throwIO (HasCallStack => InternalError -> ClientError
InternalError -> ClientError
InternalError (InternalError -> ClientError) -> InternalError -> ClientError
forall a b. (a -> b) -> a -> b
$ String -> InternalError
DeserializationError String
msg)
readBuffer :: IO BS.ByteString
readBuffer :: IO ByteString
readBuffer =
IORef ByteString -> IO ByteString
forall a. IORef a -> IO a
readIORef IORef ByteString
buff
IO ByteString -> (ByteString -> IO ByteString) -> IO ByteString
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\ByteString
currentBuffer ->
case ByteString -> Int
BS.length ByteString
currentBuffer of
Int
0 -> IO ByteString
readSock
Int
_ -> Buffer -> IO ()
flushBuffer Buffer
buffer IO () -> IO ByteString -> IO ByteString
forall a b. IO a -> IO b -> IO b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ByteString -> IO ByteString
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
currentBuffer
)
data ClientError where
UserError :: HasCallStack => UserError -> ClientError
InternalError :: HasCallStack => InternalError -> ClientError
deriving anyclass (Show ClientError
Typeable ClientError
(Typeable ClientError, Show ClientError) =>
(ClientError -> SomeException)
-> (SomeException -> Maybe ClientError)
-> (ClientError -> String)
-> Exception ClientError
SomeException -> Maybe ClientError
ClientError -> String
ClientError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: ClientError -> SomeException
toException :: ClientError -> SomeException
$cfromException :: SomeException -> Maybe ClientError
fromException :: SomeException -> Maybe ClientError
$cdisplayException :: ClientError -> String
displayException :: ClientError -> String
Exception)
instance Show ClientError where
show :: ClientError -> String
show (UserError UserError
err) = String
"UserError " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UserError -> String
forall a. Show a => a -> String
show UserError
err String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> CallStack -> String
prettyCallStack CallStack
HasCallStack => CallStack
callStack
show (InternalError InternalError
err) = String
"InternalError " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> InternalError -> String
forall a. Show a => a -> String
show InternalError
err String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> CallStack -> String
prettyCallStack CallStack
HasCallStack => CallStack
callStack
data ConnectionError
= NoAdressResolved
| EstablishTimeout
deriving (Int -> ConnectionError -> String -> String
[ConnectionError] -> String -> String
ConnectionError -> String
(Int -> ConnectionError -> String -> String)
-> (ConnectionError -> String)
-> ([ConnectionError] -> String -> String)
-> Show ConnectionError
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> ConnectionError -> String -> String
showsPrec :: Int -> ConnectionError -> String -> String
$cshow :: ConnectionError -> String
show :: ConnectionError -> String
$cshowList :: [ConnectionError] -> String -> String
showList :: [ConnectionError] -> String -> String
Show, Show ConnectionError
Typeable ConnectionError
(Typeable ConnectionError, Show ConnectionError) =>
(ConnectionError -> SomeException)
-> (SomeException -> Maybe ConnectionError)
-> (ConnectionError -> String)
-> Exception ConnectionError
SomeException -> Maybe ConnectionError
ConnectionError -> String
ConnectionError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: ConnectionError -> SomeException
toException :: ConnectionError -> SomeException
$cfromException :: SomeException -> Maybe ConnectionError
fromException :: SomeException -> Maybe ConnectionError
$cdisplayException :: ConnectionError -> String
displayException :: ConnectionError -> String
Exception)
data UserError
= UnmatchedType String
| UnmatchedColumn String
| UnmatchedColumnsCount String
| DatabaseException ExceptionPacket
deriving (Int -> UserError -> String -> String
[UserError] -> String -> String
UserError -> String
(Int -> UserError -> String -> String)
-> (UserError -> String)
-> ([UserError] -> String -> String)
-> Show UserError
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> UserError -> String -> String
showsPrec :: Int -> UserError -> String -> String
$cshow :: UserError -> String
show :: UserError -> String
$cshowList :: [UserError] -> String -> String
showList :: [UserError] -> String -> String
Show, Show UserError
Typeable UserError
(Typeable UserError, Show UserError) =>
(UserError -> SomeException)
-> (SomeException -> Maybe UserError)
-> (UserError -> String)
-> Exception UserError
SomeException -> Maybe UserError
UserError -> String
UserError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: UserError -> SomeException
toException :: UserError -> SomeException
$cfromException :: SomeException -> Maybe UserError
fromException :: SomeException -> Maybe UserError
$cdisplayException :: UserError -> String
displayException :: UserError -> String
Exception)
data InternalError
= UnexpectedPacketType UVarInt
| DeserializationError String
deriving (Int -> InternalError -> String -> String
[InternalError] -> String -> String
InternalError -> String
(Int -> InternalError -> String -> String)
-> (InternalError -> String)
-> ([InternalError] -> String -> String)
-> Show InternalError
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> InternalError -> String -> String
showsPrec :: Int -> InternalError -> String -> String
$cshow :: InternalError -> String
show :: InternalError -> String
$cshowList :: [InternalError] -> String -> String
showList :: [InternalError] -> String -> String
Show, Show InternalError
Typeable InternalError
(Typeable InternalError, Show InternalError) =>
(InternalError -> SomeException)
-> (SomeException -> Maybe InternalError)
-> (InternalError -> String)
-> Exception InternalError
SomeException -> Maybe InternalError
InternalError -> String
InternalError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: InternalError -> SomeException
toException :: InternalError -> SomeException
$cfromException :: SomeException -> Maybe InternalError
fromException :: SomeException -> Maybe InternalError
$cdisplayException :: InternalError -> String
displayException :: InternalError -> String
Exception)
data ClientPacket where
Hello :: HelloPacket -> ClientPacket
Query :: QueryPacket -> ClientPacket
Data :: DataPacket -> ClientPacket
Cancel :: ClientPacket
Ping :: ClientPacket
TablesStatusRequest :: ClientPacket
KeepAlive :: ClientPacket
Scalar :: ClientPacket
IgnoredPartUUIDs :: ClientPacket
ReadTaskResponse :: ClientPacket
MergeTreeReadTaskResponse :: ClientPacket
SSHChallengeRequest :: ClientPacket
SSHChallengeResponse :: ClientPacket
deriving ((forall x. ClientPacket -> Rep ClientPacket x)
-> (forall x. Rep ClientPacket x -> ClientPacket)
-> Generic ClientPacket
forall x. Rep ClientPacket x -> ClientPacket
forall x. ClientPacket -> Rep ClientPacket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ClientPacket -> Rep ClientPacket x
from :: forall x. ClientPacket -> Rep ClientPacket x
$cto :: forall x. Rep ClientPacket x -> ClientPacket
to :: forall x. Rep ClientPacket x -> ClientPacket
Generic)
instance Serializable ClientPacket where
serialize :: ProtocolRevision -> ClientPacket -> Builder
serialize ProtocolRevision
rev ClientPacket
packet = case ClientPacket
packet of
(Hello HelloPacket
p) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
0 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> HelloPacket -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev HelloPacket
p
(Query QueryPacket
p) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
1 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> QueryPacket -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev QueryPacket
p
(Data DataPacket
p) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
2 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> DataPacket -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev DataPacket
p
(ClientPacket
Cancel) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
3
(ClientPacket
Ping) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
4
(ClientPacket
TablesStatusRequest) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
5
(ClientPacket
KeepAlive) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
6
(ClientPacket
Scalar) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
7
(ClientPacket
IgnoredPartUUIDs) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
8
(ClientPacket
ReadTaskResponse) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
9
(ClientPacket
MergeTreeReadTaskResponse) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
10
(ClientPacket
SSHChallengeRequest) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
11
(ClientPacket
SSHChallengeResponse) -> forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev UVarInt
12
mkHelloPacket :: Text -> Text -> Text -> ClientPacket
mkHelloPacket :: Text -> Text -> Text -> ClientPacket
mkHelloPacket Text
db Text
user Text
pass = HelloPacket -> ClientPacket
Hello
MkHelloPacket
{ client_name :: ChString
client_name = ChString
clientName
, client_version_major :: UVarInt
client_version_major = UVarInt
major
, client_version_minor :: UVarInt
client_version_minor = UVarInt
minor
, tcp_protocol_version :: ProtocolRevision
tcp_protocol_version = ProtocolRevision
latestSupportedRevision
, default_database :: ChString
default_database = Text -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType Text
db
, user :: ChString
user = Text -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType Text
user
, pass :: ChString
pass = Text -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType Text
pass
}
data HelloPacket = MkHelloPacket
{ HelloPacket -> ChString
client_name :: ChString
, HelloPacket -> UVarInt
client_version_major :: UVarInt
, HelloPacket -> UVarInt
client_version_minor :: UVarInt
, HelloPacket -> ProtocolRevision
tcp_protocol_version :: ProtocolRevision
, HelloPacket -> ChString
default_database :: ChString
, HelloPacket -> ChString
user :: ChString
, HelloPacket -> ChString
pass :: ChString
}
deriving ((forall x. HelloPacket -> Rep HelloPacket x)
-> (forall x. Rep HelloPacket x -> HelloPacket)
-> Generic HelloPacket
forall x. Rep HelloPacket x -> HelloPacket
forall x. HelloPacket -> Rep HelloPacket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HelloPacket -> Rep HelloPacket x
from :: forall x. HelloPacket -> Rep HelloPacket x
$cto :: forall x. Rep HelloPacket x -> HelloPacket
to :: forall x. Rep HelloPacket x -> HelloPacket
Generic, ProtocolRevision -> HelloPacket -> Builder
(ProtocolRevision -> HelloPacket -> Builder)
-> Serializable HelloPacket
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> HelloPacket -> Builder
serialize :: ProtocolRevision -> HelloPacket -> Builder
Serializable)
data Addendum = MkAddendum{Addendum
-> SinceRevision ChString DBMS_MIN_PROTOCOL_VERSION_WITH_QUOTA_KEY
quota_key :: ChString `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_QUOTA_KEY}
deriving ((forall x. Addendum -> Rep Addendum x)
-> (forall x. Rep Addendum x -> Addendum) -> Generic Addendum
forall x. Rep Addendum x -> Addendum
forall x. Addendum -> Rep Addendum x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Addendum -> Rep Addendum x
from :: forall x. Addendum -> Rep Addendum x
$cto :: forall x. Rep Addendum x -> Addendum
to :: forall x. Rep Addendum x -> Addendum
Generic, ProtocolRevision -> Addendum -> Builder
(ProtocolRevision -> Addendum -> Builder) -> Serializable Addendum
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> Addendum -> Builder
serialize :: ProtocolRevision -> Addendum -> Builder
Serializable)
mkQueryPacket :: ConnectionState -> ChString -> ClientPacket
mkQueryPacket :: ConnectionState -> ChString -> ClientPacket
mkQueryPacket MkConnectionState{ProtocolRevision
ChString
Buffer
ConnectionArgs
user :: ConnectionState -> ChString
hostname :: ConnectionState -> ChString
os_user :: ConnectionState -> ChString
buffer :: ConnectionState -> Buffer
revision :: ConnectionState -> ProtocolRevision
creds :: ConnectionState -> ConnectionArgs
user :: ChString
hostname :: ChString
os_user :: ChString
buffer :: Buffer
revision :: ProtocolRevision
creds :: ConnectionArgs
..} ChString
query = QueryPacket -> ClientPacket
Query
MkQueryPacket
{ query_id :: ChString
query_id = ChString
""
, client_info :: SinceRevision ClientInfo DBMS_MIN_REVISION_WITH_CLIENT_INFO
client_info = ClientInfo
-> SinceRevision ClientInfo DBMS_MIN_REVISION_WITH_CLIENT_INFO
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision MkClientInfo
{ query_kind :: QueryKind
query_kind = QueryKind
InitialQuery
, initial_user :: ChString
initial_user = ChString
user
, initial_query_id :: ChString
initial_query_id = ChString
""
, initial_adress :: ChString
initial_adress = ChString
"0.0.0.0:0"
, initial_time :: SinceRevision
Int64 DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME
initial_time = Int64
-> SinceRevision
Int64 DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision Int64
0
, interface_type :: UInt8
interface_type = UInt8
1
, ChString
os_user :: ChString
os_user :: ChString
os_user, ChString
hostname :: ChString
hostname :: ChString
hostname
, client_name :: ChString
client_name = ChString
clientName
, client_version_major :: UVarInt
client_version_major = UVarInt
major
, client_version_minor :: UVarInt
client_version_minor = UVarInt
minor
, client_revision :: ProtocolRevision
client_revision = ProtocolRevision
revision
, quota_key :: SinceRevision
ChString DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO
quota_key = ChString
-> SinceRevision
ChString DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision ChString
""
, distrubuted_depth :: SinceRevision UVarInt DBMS_TCP_PROTOCOL_VERSION
distrubuted_depth = UVarInt -> SinceRevision UVarInt DBMS_TCP_PROTOCOL_VERSION
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision UVarInt
0
, client_version_patch :: SinceRevision UVarInt DBMS_MIN_REVISION_WITH_VERSION_PATCH
client_version_patch = UVarInt
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_VERSION_PATCH
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision UVarInt
patch
, open_telemetry :: SinceRevision UInt8 DBMS_MIN_REVISION_WITH_OPENTELEMETRY
open_telemetry = UInt8 -> SinceRevision UInt8 DBMS_MIN_REVISION_WITH_OPENTELEMETRY
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision UInt8
0
, collaborate_with_initiator :: SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
collaborate_with_initiator = UVarInt
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision UVarInt
0
, count_participating_replicas :: SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
count_participating_replicas = UVarInt
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision UVarInt
0
, number_of_current_replica :: SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
number_of_current_replica = UVarInt
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision UVarInt
0
}
, settings :: DbSettings
settings = DbSettings
MkDbSettings
, interserver_secret :: SinceRevision ChString DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET
interserver_secret = ChString
-> SinceRevision ChString DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision ChString
""
, query_stage :: QueryStage
query_stage = QueryStage
Complete
, compression :: UVarInt
compression = UVarInt
0
, ChString
query :: ChString
query :: ChString
query
, parameters :: SinceRevision
QueryParameters DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS
parameters = QueryParameters
-> SinceRevision
QueryParameters DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision QueryParameters
MkQueryParameters
}
data QueryPacket = MkQueryPacket
{ QueryPacket -> ChString
query_id :: ChString
, QueryPacket
-> SinceRevision ClientInfo DBMS_MIN_REVISION_WITH_CLIENT_INFO
client_info :: ClientInfo `SinceRevision` DBMS_MIN_REVISION_WITH_CLIENT_INFO
, QueryPacket -> DbSettings
settings :: DbSettings
, QueryPacket
-> SinceRevision ChString DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET
interserver_secret :: ChString `SinceRevision` DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET
, QueryPacket -> QueryStage
query_stage :: QueryStage
, QueryPacket -> UVarInt
compression :: UVarInt
, QueryPacket -> ChString
query :: ChString
, QueryPacket
-> SinceRevision
QueryParameters DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS
parameters :: QueryParameters `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS
}
deriving ((forall x. QueryPacket -> Rep QueryPacket x)
-> (forall x. Rep QueryPacket x -> QueryPacket)
-> Generic QueryPacket
forall x. Rep QueryPacket x -> QueryPacket
forall x. QueryPacket -> Rep QueryPacket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. QueryPacket -> Rep QueryPacket x
from :: forall x. QueryPacket -> Rep QueryPacket x
$cto :: forall x. Rep QueryPacket x -> QueryPacket
to :: forall x. Rep QueryPacket x -> QueryPacket
Generic, ProtocolRevision -> QueryPacket -> Builder
(ProtocolRevision -> QueryPacket -> Builder)
-> Serializable QueryPacket
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> QueryPacket -> Builder
serialize :: ProtocolRevision -> QueryPacket -> Builder
Serializable)
data DbSettings = MkDbSettings
instance Serializable DbSettings where serialize :: ProtocolRevision -> DbSettings -> Builder
serialize ProtocolRevision
rev DbSettings
_ = forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @ChString ProtocolRevision
rev ChString
""
data QueryParameters = MkQueryParameters
instance Serializable QueryParameters where serialize :: ProtocolRevision -> QueryParameters -> Builder
serialize ProtocolRevision
rev QueryParameters
_ = forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @ChString ProtocolRevision
rev ChString
""
data QueryStage
= FetchColumns | WithMergeableState | Complete
| WithMergeableStateAfterAggregation
| WithMergeableStateAfterAggregationAndLimit
deriving (Int -> QueryStage
QueryStage -> Int
QueryStage -> [QueryStage]
QueryStage -> QueryStage
QueryStage -> QueryStage -> [QueryStage]
QueryStage -> QueryStage -> QueryStage -> [QueryStage]
(QueryStage -> QueryStage)
-> (QueryStage -> QueryStage)
-> (Int -> QueryStage)
-> (QueryStage -> Int)
-> (QueryStage -> [QueryStage])
-> (QueryStage -> QueryStage -> [QueryStage])
-> (QueryStage -> QueryStage -> [QueryStage])
-> (QueryStage -> QueryStage -> QueryStage -> [QueryStage])
-> Enum QueryStage
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: QueryStage -> QueryStage
succ :: QueryStage -> QueryStage
$cpred :: QueryStage -> QueryStage
pred :: QueryStage -> QueryStage
$ctoEnum :: Int -> QueryStage
toEnum :: Int -> QueryStage
$cfromEnum :: QueryStage -> Int
fromEnum :: QueryStage -> Int
$cenumFrom :: QueryStage -> [QueryStage]
enumFrom :: QueryStage -> [QueryStage]
$cenumFromThen :: QueryStage -> QueryStage -> [QueryStage]
enumFromThen :: QueryStage -> QueryStage -> [QueryStage]
$cenumFromTo :: QueryStage -> QueryStage -> [QueryStage]
enumFromTo :: QueryStage -> QueryStage -> [QueryStage]
$cenumFromThenTo :: QueryStage -> QueryStage -> QueryStage -> [QueryStage]
enumFromThenTo :: QueryStage -> QueryStage -> QueryStage -> [QueryStage]
Enum)
instance Serializable QueryStage where
serialize :: ProtocolRevision -> QueryStage -> Builder
serialize ProtocolRevision
rev = forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev (UVarInt -> Builder)
-> (QueryStage -> UVarInt) -> QueryStage -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> UVarInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> UVarInt) -> (QueryStage -> Int) -> QueryStage -> UVarInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QueryStage -> Int
forall a. Enum a => a -> Int
fromEnum
data Flags = IMPORTANT | CUSTOM | OBSOLETE
_flagCode :: Flags -> UInt64
_flagCode :: Flags -> UInt64
_flagCode Flags
IMPORTANT = UInt64
0x01
_flagCode Flags
CUSTOM = UInt64
0x02
_flagCode Flags
OBSOLETE = UInt64
0x04
data ClientInfo = MkClientInfo
{ ClientInfo -> QueryKind
query_kind :: QueryKind
, ClientInfo -> ChString
initial_user :: ChString
, ClientInfo -> ChString
initial_query_id :: ChString
, ClientInfo -> ChString
initial_adress :: ChString
, ClientInfo
-> SinceRevision
Int64 DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME
initial_time :: Int64 `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME
, ClientInfo -> UInt8
interface_type :: UInt8
, ClientInfo -> ChString
os_user :: ChString
, ClientInfo -> ChString
hostname :: ChString
, ClientInfo -> ChString
client_name :: ChString
, ClientInfo -> UVarInt
client_version_major :: UVarInt
, ClientInfo -> UVarInt
client_version_minor :: UVarInt
, ClientInfo -> ProtocolRevision
client_revision :: ProtocolRevision
, ClientInfo
-> SinceRevision
ChString DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO
quota_key :: ChString `SinceRevision` DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO
, ClientInfo -> SinceRevision UVarInt DBMS_TCP_PROTOCOL_VERSION
distrubuted_depth :: UVarInt `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_DISTRIBUTED_DEPTH
, ClientInfo
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_VERSION_PATCH
client_version_patch :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_VERSION_PATCH
, ClientInfo
-> SinceRevision UInt8 DBMS_MIN_REVISION_WITH_OPENTELEMETRY
open_telemetry :: UInt8 `SinceRevision` DBMS_MIN_REVISION_WITH_OPENTELEMETRY
, ClientInfo
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
collaborate_with_initiator :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
, ClientInfo
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
count_participating_replicas :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
, ClientInfo
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
number_of_current_replica :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS
}
deriving ((forall x. ClientInfo -> Rep ClientInfo x)
-> (forall x. Rep ClientInfo x -> ClientInfo) -> Generic ClientInfo
forall x. Rep ClientInfo x -> ClientInfo
forall x. ClientInfo -> Rep ClientInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ClientInfo -> Rep ClientInfo x
from :: forall x. ClientInfo -> Rep ClientInfo x
$cto :: forall x. Rep ClientInfo x -> ClientInfo
to :: forall x. Rep ClientInfo x -> ClientInfo
Generic, ProtocolRevision -> ClientInfo -> Builder
(ProtocolRevision -> ClientInfo -> Builder)
-> Serializable ClientInfo
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> ClientInfo -> Builder
serialize :: ProtocolRevision -> ClientInfo -> Builder
Serializable)
data QueryKind = NoQuery | InitialQuery | SecondaryQuery
instance Serializable QueryKind where
serialize :: ProtocolRevision -> QueryKind -> Builder
serialize ProtocolRevision
rev = forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UInt8 ProtocolRevision
rev (UInt8 -> Builder) -> (QueryKind -> UInt8) -> QueryKind -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\case QueryKind
NoQuery -> UInt8
1; QueryKind
InitialQuery -> UInt8
2; QueryKind
SecondaryQuery -> UInt8
3)
mkDataPacket :: ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket :: ChString -> UVarInt -> UVarInt -> ClientPacket
mkDataPacket ChString
table_name UVarInt
columns_count UVarInt
rows_count = DataPacket -> ClientPacket
Data
MkDataPacket
{ ChString
table_name :: ChString
table_name :: ChString
table_name
, block_info :: BlockInfo
block_info = MkBlockInfo
{ field_num1 :: UVarInt
field_num1 = UVarInt
1, is_overflows :: UInt8
is_overflows = UInt8
0
, field_num2 :: UVarInt
field_num2 = UVarInt
2, bucket_num :: Int32
bucket_num = -Int32
1
, eof :: UVarInt
eof = UVarInt
0
}
, UVarInt
columns_count :: UVarInt
columns_count :: UVarInt
columns_count
, UVarInt
rows_count :: UVarInt
rows_count :: UVarInt
rows_count
}
data DataPacket = MkDataPacket
{ DataPacket -> ChString
table_name :: ChString
, DataPacket -> BlockInfo
block_info :: BlockInfo
, DataPacket -> UVarInt
columns_count :: UVarInt
, DataPacket -> UVarInt
rows_count :: UVarInt
}
deriving ((forall x. DataPacket -> Rep DataPacket x)
-> (forall x. Rep DataPacket x -> DataPacket) -> Generic DataPacket
forall x. Rep DataPacket x -> DataPacket
forall x. DataPacket -> Rep DataPacket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DataPacket -> Rep DataPacket x
from :: forall x. DataPacket -> Rep DataPacket x
$cto :: forall x. Rep DataPacket x -> DataPacket
to :: forall x. Rep DataPacket x -> DataPacket
Generic, ProtocolRevision -> DataPacket -> Builder
(ProtocolRevision -> DataPacket -> Builder)
-> Serializable DataPacket
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> DataPacket -> Builder
serialize :: ProtocolRevision -> DataPacket -> Builder
Serializable, ProtocolRevision -> Get DataPacket
(ProtocolRevision -> Get DataPacket) -> Deserializable DataPacket
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get DataPacket
deserialize :: ProtocolRevision -> Get DataPacket
Deserializable)
data BlockInfo = MkBlockInfo
{ BlockInfo -> UVarInt
field_num1 :: UVarInt, BlockInfo -> UInt8
is_overflows :: UInt8
, BlockInfo -> UVarInt
field_num2 :: UVarInt, BlockInfo -> Int32
bucket_num :: Int32
, BlockInfo -> UVarInt
eof :: UVarInt
}
deriving ((forall x. BlockInfo -> Rep BlockInfo x)
-> (forall x. Rep BlockInfo x -> BlockInfo) -> Generic BlockInfo
forall x. Rep BlockInfo x -> BlockInfo
forall x. BlockInfo -> Rep BlockInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlockInfo -> Rep BlockInfo x
from :: forall x. BlockInfo -> Rep BlockInfo x
$cto :: forall x. Rep BlockInfo x -> BlockInfo
to :: forall x. Rep BlockInfo x -> BlockInfo
Generic, ProtocolRevision -> BlockInfo -> Builder
(ProtocolRevision -> BlockInfo -> Builder)
-> Serializable BlockInfo
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> BlockInfo -> Builder
serialize :: ProtocolRevision -> BlockInfo -> Builder
Serializable, ProtocolRevision -> Get BlockInfo
(ProtocolRevision -> Get BlockInfo) -> Deserializable BlockInfo
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get BlockInfo
deserialize :: ProtocolRevision -> Get BlockInfo
Deserializable)
data ServerPacket where
HelloResponse :: HelloResponse -> ServerPacket
DataResponse :: DataPacket -> ServerPacket
Exception :: ExceptionPacket -> ServerPacket
Progress :: ProgressPacket -> ServerPacket
Pong :: ServerPacket
EndOfStream :: ServerPacket
ProfileInfo :: ProfileInfo -> ServerPacket
Totals :: ServerPacket
Extremes :: ServerPacket
TablesStatusResponse :: ServerPacket
Log :: ServerPacket
TableColumns :: TableColumns -> ServerPacket
UUIDs :: ServerPacket
ReadTaskRequest :: ServerPacket
ProfileEvents :: ServerPacket
UnknownPacket :: UVarInt -> ServerPacket
instance Deserializable ServerPacket where
deserialize :: ProtocolRevision -> Get ServerPacket
deserialize ProtocolRevision
rev = do
UVarInt
packetNum <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UVarInt ProtocolRevision
rev
case UVarInt
packetNum of
UVarInt
0 -> HelloResponse -> ServerPacket
HelloResponse (HelloResponse -> ServerPacket)
-> Get HelloResponse -> Get ServerPacket
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get HelloResponse
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev
UVarInt
1 -> DataPacket -> ServerPacket
DataResponse (DataPacket -> ServerPacket) -> Get DataPacket -> Get ServerPacket
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get DataPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev
UVarInt
2 -> ExceptionPacket -> ServerPacket
Exception (ExceptionPacket -> ServerPacket)
-> Get ExceptionPacket -> Get ServerPacket
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get ExceptionPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev
UVarInt
3 -> ProgressPacket -> ServerPacket
Progress (ProgressPacket -> ServerPacket)
-> Get ProgressPacket -> Get ServerPacket
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get ProgressPacket
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev
UVarInt
4 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
Pong
UVarInt
5 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
EndOfStream
UVarInt
6 -> ProfileInfo -> ServerPacket
ProfileInfo (ProfileInfo -> ServerPacket)
-> Get ProfileInfo -> Get ServerPacket
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get ProfileInfo
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev
UVarInt
7 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
Totals
UVarInt
8 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
Extremes
UVarInt
9 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
TablesStatusResponse
UVarInt
10 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
Log
UVarInt
11 -> TableColumns -> ServerPacket
TableColumns (TableColumns -> ServerPacket)
-> Get TableColumns -> Get ServerPacket
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get TableColumns
forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev
UVarInt
12 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
UUIDs
UVarInt
13 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
ReadTaskRequest
UVarInt
14 -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ServerPacket
ProfileEvents
UVarInt
_ -> ServerPacket -> Get ServerPacket
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ServerPacket -> Get ServerPacket)
-> ServerPacket -> Get ServerPacket
forall a b. (a -> b) -> a -> b
$ UVarInt -> ServerPacket
UnknownPacket UVarInt
packetNum
serverPacketToNum :: ServerPacket -> UVarInt
serverPacketToNum :: ServerPacket -> UVarInt
serverPacketToNum = \case
(HelloResponse HelloResponse
_) -> UVarInt
0; (DataResponse DataPacket
_) -> UVarInt
1
(Exception ExceptionPacket
_) -> UVarInt
2; (Progress ProgressPacket
_) -> UVarInt
3;
(ServerPacket
Pong) -> UVarInt
4; (ServerPacket
EndOfStream) -> UVarInt
5
(ProfileInfo ProfileInfo
_) -> UVarInt
6; (ServerPacket
Totals) -> UVarInt
7
(ServerPacket
Extremes) -> UVarInt
8; (ServerPacket
TablesStatusResponse) -> UVarInt
9
(ServerPacket
Log) -> UVarInt
10; (TableColumns TableColumns
_) -> UVarInt
11;
(ServerPacket
UUIDs) -> UVarInt
12; (ServerPacket
ReadTaskRequest) -> UVarInt
13
(ServerPacket
ProfileEvents) -> UVarInt
14; (UnknownPacket UVarInt
num) -> UVarInt
num
data HelloResponse = MkHelloResponse
{ HelloResponse -> ChString
server_name :: ChString
, HelloResponse -> UVarInt
server_version_major :: UVarInt
, HelloResponse -> UVarInt
server_version_minor :: UVarInt
, HelloResponse -> ProtocolRevision
server_revision :: ProtocolRevision
, HelloResponse
-> SinceRevision
UVarInt DBMS_MIN_REVISION_WITH_VERSIONED_PARALLEL_REPLICAS_PROTOCOL
server_parallel_replicas_proto :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_VERSIONED_PARALLEL_REPLICAS_PROTOCOL
, HelloResponse
-> SinceRevision ChString DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE
server_timezone :: ChString `SinceRevision` DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE
, HelloResponse
-> SinceRevision
ChString DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME
server_display_name :: ChString `SinceRevision` DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME
, HelloResponse
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_VERSION_PATCH
server_version_patch :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_VERSION_PATCH
, HelloResponse
-> SinceRevision
ChString DBMS_MIN_PROTOCOL_VERSION_WITH_CHUNKED_PACKETS
proto_send_chunked_srv :: ChString `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_CHUNKED_PACKETS
, HelloResponse
-> SinceRevision
ChString DBMS_MIN_PROTOCOL_VERSION_WITH_CHUNKED_PACKETS
proto_recv_chunked_srv :: ChString `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_CHUNKED_PACKETS
, HelloResponse
-> SinceRevision
[PasswordComplexityRules]
DBMS_MIN_PROTOCOL_VERSION_WITH_PASSWORD_COMPLEXITY_RULES
password_complexity_rules :: [PasswordComplexityRules] `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_PASSWORD_COMPLEXITY_RULES
, HelloResponse
-> SinceRevision
UInt64 DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET_V2
read_nonce :: UInt64 `SinceRevision` DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET_V2
}
deriving ((forall x. HelloResponse -> Rep HelloResponse x)
-> (forall x. Rep HelloResponse x -> HelloResponse)
-> Generic HelloResponse
forall x. Rep HelloResponse x -> HelloResponse
forall x. HelloResponse -> Rep HelloResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HelloResponse -> Rep HelloResponse x
from :: forall x. HelloResponse -> Rep HelloResponse x
$cto :: forall x. Rep HelloResponse x -> HelloResponse
to :: forall x. Rep HelloResponse x -> HelloResponse
Generic, ProtocolRevision -> Get HelloResponse
(ProtocolRevision -> Get HelloResponse)
-> Deserializable HelloResponse
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get HelloResponse
deserialize :: ProtocolRevision -> Get HelloResponse
Deserializable)
data PasswordComplexityRules = MkPasswordComplexityRules
{ PasswordComplexityRules -> ChString
original_pattern :: ChString
, PasswordComplexityRules -> ChString
exception_message :: ChString
}
deriving ((forall x.
PasswordComplexityRules -> Rep PasswordComplexityRules x)
-> (forall x.
Rep PasswordComplexityRules x -> PasswordComplexityRules)
-> Generic PasswordComplexityRules
forall x. Rep PasswordComplexityRules x -> PasswordComplexityRules
forall x. PasswordComplexityRules -> Rep PasswordComplexityRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PasswordComplexityRules -> Rep PasswordComplexityRules x
from :: forall x. PasswordComplexityRules -> Rep PasswordComplexityRules x
$cto :: forall x. Rep PasswordComplexityRules x -> PasswordComplexityRules
to :: forall x. Rep PasswordComplexityRules x -> PasswordComplexityRules
Generic, ProtocolRevision -> Get PasswordComplexityRules
(ProtocolRevision -> Get PasswordComplexityRules)
-> Deserializable PasswordComplexityRules
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get PasswordComplexityRules
deserialize :: ProtocolRevision -> Get PasswordComplexityRules
Deserializable)
instance Deserializable [PasswordComplexityRules] where
deserialize :: ProtocolRevision -> Get [PasswordComplexityRules]
deserialize ProtocolRevision
rev = do
UVarInt
len <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UVarInt ProtocolRevision
rev
Int -> Get PasswordComplexityRules -> Get [PasswordComplexityRules]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (UVarInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral UVarInt
len) (forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @PasswordComplexityRules ProtocolRevision
rev)
data ExceptionPacket = MkExceptionPacket
{ ExceptionPacket -> Int32
code :: Int32
, ExceptionPacket -> ChString
name :: ChString
, ExceptionPacket -> ChString
message :: ChString
, ExceptionPacket -> ChString
stack_trace :: ChString
, ExceptionPacket -> UInt8
nested :: UInt8
}
deriving ((forall x. ExceptionPacket -> Rep ExceptionPacket x)
-> (forall x. Rep ExceptionPacket x -> ExceptionPacket)
-> Generic ExceptionPacket
forall x. Rep ExceptionPacket x -> ExceptionPacket
forall x. ExceptionPacket -> Rep ExceptionPacket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ExceptionPacket -> Rep ExceptionPacket x
from :: forall x. ExceptionPacket -> Rep ExceptionPacket x
$cto :: forall x. Rep ExceptionPacket x -> ExceptionPacket
to :: forall x. Rep ExceptionPacket x -> ExceptionPacket
Generic, Int -> ExceptionPacket -> String -> String
[ExceptionPacket] -> String -> String
ExceptionPacket -> String
(Int -> ExceptionPacket -> String -> String)
-> (ExceptionPacket -> String)
-> ([ExceptionPacket] -> String -> String)
-> Show ExceptionPacket
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> ExceptionPacket -> String -> String
showsPrec :: Int -> ExceptionPacket -> String -> String
$cshow :: ExceptionPacket -> String
show :: ExceptionPacket -> String
$cshowList :: [ExceptionPacket] -> String -> String
showList :: [ExceptionPacket] -> String -> String
Show, ProtocolRevision -> Get ExceptionPacket
(ProtocolRevision -> Get ExceptionPacket)
-> Deserializable ExceptionPacket
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get ExceptionPacket
deserialize :: ProtocolRevision -> Get ExceptionPacket
Deserializable)
data ProgressPacket = MkProgressPacket
{ ProgressPacket -> UVarInt
rows :: UVarInt
, ProgressPacket -> UVarInt
bytes :: UVarInt
, ProgressPacket -> UVarInt
total_rows :: UVarInt
, ProgressPacket
-> SinceRevision
UVarInt DBMS_MIN_PROTOCOL_VERSION_WITH_TOTAL_BYTES_IN_PROGRESS
total_bytes :: UVarInt `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_TOTAL_BYTES_IN_PROGRESS
, ProgressPacket
-> SinceRevision
UVarInt DBMS_MIN_PROTOCOL_VERSION_WITH_TOTAL_BYTES_IN_PROGRESS
wrote_rows :: UVarInt `SinceRevision` DBMS_MIN_PROTOCOL_VERSION_WITH_TOTAL_BYTES_IN_PROGRESS
, ProgressPacket
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO
wrote_bytes :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO
, ProgressPacket
-> SinceRevision UVarInt DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO
elapsed_ns :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO
}
deriving ((forall x. ProgressPacket -> Rep ProgressPacket x)
-> (forall x. Rep ProgressPacket x -> ProgressPacket)
-> Generic ProgressPacket
forall x. Rep ProgressPacket x -> ProgressPacket
forall x. ProgressPacket -> Rep ProgressPacket x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ProgressPacket -> Rep ProgressPacket x
from :: forall x. ProgressPacket -> Rep ProgressPacket x
$cto :: forall x. Rep ProgressPacket x -> ProgressPacket
to :: forall x. Rep ProgressPacket x -> ProgressPacket
Generic, ProtocolRevision -> Get ProgressPacket
(ProtocolRevision -> Get ProgressPacket)
-> Deserializable ProgressPacket
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get ProgressPacket
deserialize :: ProtocolRevision -> Get ProgressPacket
Deserializable)
data ProfileInfo = MkProfileInfo
{ ProfileInfo -> UVarInt
rows :: UVarInt
, ProfileInfo -> UVarInt
blocks :: UVarInt
, ProfileInfo -> UVarInt
bytes :: UVarInt
, ProfileInfo -> UInt8
applied_limit :: UInt8
, ProfileInfo -> UVarInt
rows_before_limit :: UVarInt
, ProfileInfo -> UInt8
calculated_rows_before_limit :: UInt8
, ProfileInfo
-> SinceRevision
UInt8 DBMS_MIN_REVISION_WITH_ROWS_BEFORE_AGGREGATION
applied_aggregation :: UInt8 `SinceRevision` DBMS_MIN_REVISION_WITH_ROWS_BEFORE_AGGREGATION
, ProfileInfo
-> SinceRevision
UVarInt DBMS_MIN_REVISION_WITH_ROWS_BEFORE_AGGREGATION
rows_before_aggregation :: UVarInt `SinceRevision` DBMS_MIN_REVISION_WITH_ROWS_BEFORE_AGGREGATION
}
deriving ((forall x. ProfileInfo -> Rep ProfileInfo x)
-> (forall x. Rep ProfileInfo x -> ProfileInfo)
-> Generic ProfileInfo
forall x. Rep ProfileInfo x -> ProfileInfo
forall x. ProfileInfo -> Rep ProfileInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ProfileInfo -> Rep ProfileInfo x
from :: forall x. ProfileInfo -> Rep ProfileInfo x
$cto :: forall x. Rep ProfileInfo x -> ProfileInfo
to :: forall x. Rep ProfileInfo x -> ProfileInfo
Generic, ProtocolRevision -> Get ProfileInfo
(ProtocolRevision -> Get ProfileInfo) -> Deserializable ProfileInfo
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get ProfileInfo
deserialize :: ProtocolRevision -> Get ProfileInfo
Deserializable)
data TableColumns = MkTableColumns
{ TableColumns -> ChString
table_name :: ChString
, TableColumns -> ChString
table_columns :: ChString
}
deriving ((forall x. TableColumns -> Rep TableColumns x)
-> (forall x. Rep TableColumns x -> TableColumns)
-> Generic TableColumns
forall x. Rep TableColumns x -> TableColumns
forall x. TableColumns -> Rep TableColumns x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TableColumns -> Rep TableColumns x
from :: forall x. TableColumns -> Rep TableColumns x
$cto :: forall x. Rep TableColumns x -> TableColumns
to :: forall x. Rep TableColumns x -> TableColumns
Generic, ProtocolRevision -> Get TableColumns
(ProtocolRevision -> Get TableColumns)
-> Deserializable TableColumns
forall chType.
(ProtocolRevision -> Get chType) -> Deserializable chType
$cdeserialize :: ProtocolRevision -> Get TableColumns
deserialize :: ProtocolRevision -> Get TableColumns
Deserializable)
type GenericClickHaskell record hasColumns =
( Generic record
, GClickHaskell hasColumns (Rep record)
)
class ClickHaskell columns record
where
default deserializeColumns :: GenericClickHaskell record columns => Bool -> ProtocolRevision -> UVarInt -> Get [record]
deserializeColumns :: Bool -> ProtocolRevision -> UVarInt -> Get [record]
deserializeColumns Bool
isCheckRequired ProtocolRevision
rev UVarInt
size = do
[Rep record Any]
list <- forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
Bool -> ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @columns Bool
isCheckRequired ProtocolRevision
rev UVarInt
size
[record] -> Get [record]
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([record] -> Get [record]) -> [record] -> Get [record]
forall a b. (a -> b) -> a -> b
$ do
Rep record Any
element <- [Rep record Any]
list
case Rep record Any -> record
forall a x. Generic a => Rep a x -> a
forall x. Rep record x -> record
to Rep record Any
element of record
res -> record -> [record]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (record -> [record]) -> record -> [record]
forall a b. (a -> b) -> a -> b
$! record
res
default columns :: GenericClickHaskell record columns => Builder
columns :: Builder
columns = [(Builder, Builder)] -> Builder
forall {a} {b}. (Monoid a, IsString a) => [(a, b)] -> a
buildCols (forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
[(Builder, Builder)]
gReadingColumns @columns @(Rep record))
where
buildCols :: [(a, b)] -> a
buildCols [] = a
forall a. Monoid a => a
mempty
buildCols ((a
col, b
_):[]) = a
col
buildCols ((a
col, b
_):[(a, b)]
rest) = a
col a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
", " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> [(a, b)] -> a
buildCols [(a, b)]
rest
default readingColumnsAndTypes :: GenericClickHaskell record columns => Builder
readingColumnsAndTypes :: Builder
readingColumnsAndTypes = [(Builder, Builder)] -> Builder
forall {a}. (Monoid a, IsString a) => [(a, a)] -> a
buildColsTypes (forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
[(Builder, Builder)]
gReadingColumns @columns @(Rep record))
where
buildColsTypes :: [(a, a)] -> a
buildColsTypes [] = a
forall a. Monoid a => a
mempty
buildColsTypes ((a
col, a
typ):[]) = a
col a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
" " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
typ
buildColsTypes ((a
col, a
typ):[(a, a)]
rest) = a
col a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
" " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
typ a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
", " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> [(a, a)] -> a
buildColsTypes [(a, a)]
rest
default serializeRecords :: GenericClickHaskell record columns => [record] -> ProtocolRevision -> Builder
serializeRecords :: [record] -> ProtocolRevision -> Builder
serializeRecords [record]
records ProtocolRevision
rev = forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
ProtocolRevision -> [f p] -> Builder
gSerializeRecords @columns ProtocolRevision
rev ((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 [record]
records)
default columnsCount :: GenericClickHaskell record columns => UVarInt
columnsCount :: UVarInt
columnsCount = forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
UVarInt
gColumnsCount @columns @(Rep record)
class GClickHaskell (columns :: [Type]) f
where
gFromColumns :: Bool -> ProtocolRevision -> UVarInt -> Get [f p]
gReadingColumns :: [(Builder, Builder)]
gSerializeRecords :: ProtocolRevision -> [f p] -> Builder
gColumnsCount :: UVarInt
instance
GClickHaskell columns f
=>
GClickHaskell columns (D1 c (C1 c2 f))
where
{-# INLINE gFromColumns #-}
gFromColumns :: forall p.
Bool -> ProtocolRevision -> UVarInt -> Get [D1 c (C1 c2 f) p]
gFromColumns Bool
isCheckRequired 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.
GClickHaskell columns f =>
Bool -> ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @columns Bool
isCheckRequired ProtocolRevision
rev UVarInt
size
gReadingColumns :: [(Builder, Builder)]
gReadingColumns = forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
[(Builder, Builder)]
gReadingColumns @columns @f
{-# INLINE gSerializeRecords #-}
gSerializeRecords :: forall p. ProtocolRevision -> [D1 c (C1 c2 f) p] -> Builder
gSerializeRecords ProtocolRevision
rev = forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
ProtocolRevision -> [f p] -> Builder
gSerializeRecords @columns ProtocolRevision
rev ([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)
gColumnsCount :: UVarInt
gColumnsCount = forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
UVarInt
gColumnsCount @columns @f
instance
(GClickHaskell columns left, GClickHaskell columns right)
=>
GClickHaskell columns (left :*: right)
where
{-# INLINE gFromColumns #-}
gFromColumns :: forall p.
Bool -> ProtocolRevision -> UVarInt -> Get [(:*:) left right p]
gFromColumns Bool
isCheckRequired ProtocolRevision
rev UVarInt
size =
([left p] -> [right p] -> [(:*:) left right p])
-> Get [left p] -> Get [right p] -> Get [(:*:) left right p]
forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((left p -> right p -> (:*:) left right p)
-> [left p] -> [right p] -> [(:*:) left right p]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith left p -> right p -> (:*:) left right p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:))
(forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
Bool -> ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @columns @left Bool
isCheckRequired ProtocolRevision
rev UVarInt
size)
(forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
Bool -> ProtocolRevision -> UVarInt -> Get [f p]
gFromColumns @columns @right Bool
isCheckRequired ProtocolRevision
rev UVarInt
size)
gReadingColumns :: [(Builder, Builder)]
gReadingColumns = forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
[(Builder, Builder)]
gReadingColumns @columns @left [(Builder, Builder)]
-> [(Builder, Builder)] -> [(Builder, Builder)]
forall a. [a] -> [a] -> [a]
++ forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
[(Builder, Builder)]
gReadingColumns @columns @right
{-# INLINE gSerializeRecords #-}
gSerializeRecords :: forall p. ProtocolRevision -> [(:*:) left right p] -> Builder
gSerializeRecords ProtocolRevision
rev [(:*:) left right p]
xs =
(\([left p]
ls,[right p]
rs) -> forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
ProtocolRevision -> [f p] -> Builder
gSerializeRecords @columns ProtocolRevision
rev [left p]
ls Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (columns :: [*]) (f :: * -> *) p.
GClickHaskell columns f =>
ProtocolRevision -> [f p] -> Builder
gSerializeRecords @columns ProtocolRevision
rev [right p]
rs)
(((:*:) left right p
-> ([left p], [right p]) -> ([left p], [right p]))
-> ([left p], [right p])
-> [(:*:) left right p]
-> ([left p], [right p])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(left p
l :*: right p
r) ([left p]
accL, [right p]
accR) -> (left p
lleft p -> [left p] -> [left p]
forall a. a -> [a] -> [a]
:[left p]
accL, right p
rright p -> [right p] -> [right p]
forall a. a -> [a] -> [a]
:[right p]
accR)) ([], []) [(:*:) left right p]
xs)
gColumnsCount :: UVarInt
gColumnsCount = forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
UVarInt
gColumnsCount @columns @left UVarInt -> UVarInt -> UVarInt
forall a. Num a => a -> a -> a
+ forall (columns :: [*]) (f :: * -> *).
GClickHaskell columns f =>
UVarInt
gColumnsCount @columns @right
instance
( KnownColumn (Column name chType)
, SerializableColumn (Column name chType)
, FromChType chType inputType
, ToChType chType inputType
, Column name chType ~ TakeColumn name columns
) => GClickHaskell columns ((S1 (MetaSel (Just name) a b f)) (Rec0 inputType))
where
{-# INLINE gFromColumns #-}
gFromColumns :: forall p.
Bool
-> ProtocolRevision
-> UVarInt
-> Get [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p]
gFromColumns Bool
isCheckRequired 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.
SerializableColumn column =>
ProtocolRevision -> Bool -> UVarInt -> Get column
deserializeColumn @(Column name chType) ProtocolRevision
rev Bool
isCheckRequired UVarInt
size
gReadingColumns :: [(Builder, Builder)]
gReadingColumns = (forall column. KnownColumn column => Builder
renderColumnName @(Column name chType), forall column. KnownColumn column => Builder
renderColumnType @(Column name chType)) (Builder, Builder) -> [(Builder, Builder)] -> [(Builder, Builder)]
forall a. a -> [a] -> [a]
: []
{-# INLINE gSerializeRecords #-}
gSerializeRecords :: forall p.
ProtocolRevision
-> [S1 ('MetaSel ('Just name) a b f) (Rec0 inputType) p] -> Builder
gSerializeRecords ProtocolRevision
rev = ProtocolRevision -> Column name chType -> Builder
forall column.
SerializableColumn column =>
ProtocolRevision -> column -> Builder
serializeColumn 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 =>
[GetColumnType column]
-> Column (GetColumnName column) (GetColumnType column)
mkColumn @(Column name chType) ([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)
gColumnsCount :: UVarInt
gColumnsCount = UVarInt
1
type family
TakeColumn (name :: Symbol) (columns :: [Type]) :: Type
where
TakeColumn name columns = GoTakeColumn name columns '[]
type family
GoTakeColumn name (columns :: [Type]) (acc :: [Type]) :: Type
where
GoTakeColumn name (Column name chType ': columns) acc = Column name chType
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"
)
{-# SPECIALIZE replicateM :: Int -> Get chType -> Get [chType] #-}
class SerializableColumn column where
deserializeColumn :: ProtocolRevision -> Bool -> UVarInt -> Get column
serializeColumn :: ProtocolRevision -> column -> Builder
handleColumnHeader :: forall column . KnownColumn column => ProtocolRevision -> Bool -> Get ()
handleColumnHeader :: forall column.
KnownColumn column =>
ProtocolRevision -> Bool -> Get ()
handleColumnHeader ProtocolRevision
rev Bool
isCheckRequired = do
let expectedColumnName :: ChString
expectedColumnName = Builder -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (forall column. KnownColumn column => Builder
renderColumnName @column)
ChString
resultColumnName <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @ChString ProtocolRevision
rev
Bool -> Get () -> Get ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
isCheckRequired Bool -> Bool -> Bool
&& ChString
resultColumnName ChString -> ChString -> Bool
forall a. Eq a => a -> a -> Bool
/= ChString
expectedColumnName)
(Get () -> Get ()) -> (String -> Get ()) -> String -> Get ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientError -> Get ()
forall a e. Exception e => e -> a
throw (ClientError -> Get ())
-> (String -> ClientError) -> String -> Get ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError)
-> (String -> UserError) -> String -> ClientError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> UserError
UnmatchedColumn
(String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ String
"Got column \"" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ChString -> String
forall a. Show a => a -> String
show ChString
resultColumnName String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\" but expected \"" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ChString -> String
forall a. Show a => a -> String
show ChString
expectedColumnName String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\""
let expectedType :: ChString
expectedType = Builder -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (forall column. KnownColumn column => Builder
renderColumnType @column)
ChString
resultType <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @ChString ProtocolRevision
rev
Bool -> Get () -> Get ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
isCheckRequired Bool -> Bool -> Bool
&& ChString
resultType ChString -> ChString -> Bool
forall a. Eq a => a -> a -> Bool
/= ChString
expectedType)
(Get () -> Get ()) -> (String -> Get ()) -> String -> Get ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientError -> Get ()
forall a e. Exception e => e -> a
throw (ClientError -> Get ())
-> (String -> ClientError) -> String -> Get ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasCallStack => UserError -> ClientError
UserError -> ClientError
UserError (UserError -> ClientError)
-> (String -> UserError) -> String -> ClientError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> UserError
UnmatchedType
(String -> Get ()) -> String -> Get ()
forall a b. (a -> b) -> a -> b
$ String
"Column " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ChString -> String
forall a. Show a => a -> String
show ChString
resultColumnName String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" has type " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ChString -> String
forall a. Show a => a -> String
show ChString
resultType String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
". But expected type is " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> ChString -> String
forall a. Show a => a -> String
show ChString
expectedType
SinceRevision UInt8 DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION
_isCustom <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @(UInt8 `SinceRevision` DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION) ProtocolRevision
rev
() -> Get ()
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
instance
( KnownColumn (Column name chType)
, Deserializable chType
, Serializable chType
, IsChType chType
) =>
SerializableColumn (Column name chType) where
{-# INLINE deserializeColumn #-}
deserializeColumn :: ProtocolRevision -> Bool -> UVarInt -> Get (Column name chType)
deserializeColumn ProtocolRevision
rev Bool
isCheckRequired UVarInt
rows = do
forall column.
KnownColumn column =>
ProtocolRevision -> Bool -> Get ()
handleColumnHeader @(Column name chType) ProtocolRevision
rev Bool
isCheckRequired
forall column.
KnownColumn column =>
[GetColumnType column]
-> Column (GetColumnName column) (GetColumnType column)
mkColumn @(Column name chType)
([chType] -> Column name chType)
-> Get [chType] -> Get (Column name chType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Get chType -> Get [chType]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (UVarInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral UVarInt
rows) (forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev)
{-# INLINE serializeColumn #-}
serializeColumn :: ProtocolRevision -> Column name chType -> Builder
serializeColumn ProtocolRevision
rev Column name chType
column
= ProtocolRevision -> ChString -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @ChString (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$ forall column. KnownColumn column => Builder
renderColumnName @(Column name chType))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> ChString -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @ChString (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$ forall column. KnownColumn column => Builder
renderColumnType @(Column name chType))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (rev :: Nat) monoid.
(KnownNat rev, Monoid monoid) =>
ProtocolRevision -> monoid -> monoid
afterRevision @DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION ProtocolRevision
rev (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UInt8 ProtocolRevision
rev UInt8
0)
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ((chType -> Builder) -> [chType] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @chType ProtocolRevision
rev) (Column name chType -> [chType]
forall (name :: Symbol) chType. Column name chType -> [chType]
columnValues Column name chType
column))
instance {-# OVERLAPPING #-}
( KnownColumn (Column name (Nullable chType))
, Deserializable chType
, Serializable chType
, IsChType chType
) =>
SerializableColumn (Column name (Nullable chType)) where
{-# INLINE deserializeColumn #-}
deserializeColumn :: ProtocolRevision
-> Bool -> UVarInt -> Get (Column name (Nullable chType))
deserializeColumn ProtocolRevision
rev Bool
isCheckRequired UVarInt
rows = do
forall column.
KnownColumn column =>
ProtocolRevision -> Bool -> Get ()
handleColumnHeader @(Column name (Nullable chType)) ProtocolRevision
rev Bool
isCheckRequired
[UInt8]
nulls <- Int -> Get UInt8 -> Get [UInt8]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (UVarInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral UVarInt
rows) (forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UInt8 ProtocolRevision
rev)
forall column.
KnownColumn column =>
[GetColumnType column]
-> Column (GetColumnName column) (GetColumnType column)
mkColumn @(Column name (Nullable chType)) ([Nullable chType] -> Column name (Nullable chType))
-> Get [Nullable chType] -> Get (Column name (Nullable chType))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
[UInt8]
-> (UInt8 -> Get (Nullable chType)) -> Get [Nullable chType]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM
[UInt8]
nulls
(\case
UInt8
0 -> chType -> Nullable chType
forall a. a -> Maybe a
Just (chType -> Nullable chType) -> Get chType -> Get (Nullable chType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev
UInt8
_ -> (Nullable chType
forall a. Maybe a
Nothing Nullable chType -> Get chType -> Get (Nullable chType)
forall a b. a -> Get b -> Get a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev)
)
{-# INLINE serializeColumn #-}
serializeColumn :: ProtocolRevision -> Column name (Nullable chType) -> Builder
serializeColumn ProtocolRevision
rev Column name (Nullable chType)
column
= ProtocolRevision -> ChString -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @ChString (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$ forall column. KnownColumn column => Builder
renderColumnName @(Column name (Nullable chType)))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> ChString -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @ChString (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$ forall column. KnownColumn column => Builder
renderColumnType @(Column name (Nullable chType)))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (rev :: Nat) monoid.
(KnownNat rev, Monoid monoid) =>
ProtocolRevision -> monoid -> monoid
afterRevision @DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION ProtocolRevision
rev (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UInt8 ProtocolRevision
rev UInt8
0)
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ((Nullable chType -> Builder) -> [Nullable chType] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UInt8 ProtocolRevision
rev (UInt8 -> Builder)
-> (Nullable chType -> UInt8) -> Nullable chType -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt8 -> (chType -> UInt8) -> Nullable chType -> UInt8
forall b a. b -> (a -> b) -> Maybe a -> b
maybe UInt8
1 (UInt8 -> chType -> UInt8
forall a b. a -> b -> a
const UInt8
0)) (Column name (Nullable chType) -> [Nullable chType]
forall (name :: Symbol) chType. Column name chType -> [chType]
columnValues Column name (Nullable chType)
column))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ((Nullable chType -> Builder) -> [Nullable chType] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @chType ProtocolRevision
rev (chType -> Builder)
-> (Nullable chType -> chType) -> Nullable chType -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. chType -> (chType -> chType) -> Nullable chType -> chType
forall b a. b -> (a -> b) -> Maybe a -> b
maybe chType
forall chType. IsChType chType => chType
defaultValueOfTypeName chType -> chType
forall a. a -> a
id) (Column name (Nullable chType) -> [Nullable chType]
forall (name :: Symbol) chType. Column name chType -> [chType]
columnValues Column name (Nullable chType)
column))
instance {-# OVERLAPPING #-}
( KnownColumn (Column name (LowCardinality chType))
, Deserializable chType
, IsLowCardinalitySupported chType
, TypeError ('Text "LowCardinality deserialization still unsupported")
) =>
SerializableColumn (Column name (LowCardinality chType)) where
{-# INLINE deserializeColumn #-}
deserializeColumn :: ProtocolRevision
-> Bool -> UVarInt -> Get (Column name (LowCardinality chType))
deserializeColumn ProtocolRevision
rev Bool
isCheckRequired UVarInt
rows = do
forall column.
KnownColumn column =>
ProtocolRevision -> Bool -> Get ()
handleColumnHeader @(Column name (LowCardinality chType)) ProtocolRevision
rev Bool
isCheckRequired
UInt64
_serializationType <- (UInt64 -> UInt64 -> UInt64
forall a. Bits a => a -> a -> a
.&. UInt64
0xf) (UInt64 -> UInt64) -> Get UInt64 -> Get UInt64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UInt64 ProtocolRevision
rev
Int64
_index_size <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @Int64 ProtocolRevision
rev
forall column.
KnownColumn column =>
[GetColumnType column]
-> Column (GetColumnName column) (GetColumnType column)
mkColumn @(Column name (LowCardinality chType))
([LowCardinality chType] -> Column name (LowCardinality chType))
-> Get [LowCardinality chType]
-> Get (Column name (LowCardinality chType))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Get (LowCardinality chType) -> Get [LowCardinality chType]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (UVarInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral UVarInt
rows) (chType -> LowCardinality chType
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (chType -> LowCardinality chType)
-> Get chType -> Get (LowCardinality chType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev)
{-# INLINE serializeColumn #-}
serializeColumn :: ProtocolRevision -> Column name (LowCardinality chType) -> Builder
serializeColumn ProtocolRevision
rev (LowCardinalityColumn [chType]
column)
= ProtocolRevision -> ChString -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @ChString (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$ forall column. KnownColumn column => Builder
renderColumnName @(Column name (Nullable chType)))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> ChString -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @ChString (Builder -> ChString) -> Builder -> ChString
forall a b. (a -> b) -> a -> b
$ forall column. KnownColumn column => Builder
renderColumnType @(Column name (Nullable chType)))
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> forall (rev :: Nat) monoid.
(KnownNat rev, Monoid monoid) =>
ProtocolRevision -> monoid -> monoid
afterRevision @DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION ProtocolRevision
rev (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UInt8 ProtocolRevision
rev UInt8
0)
Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> [chType] -> Builder
forall a. HasCallStack => a
undefined [chType]
column
instance {-# OVERLAPPING #-}
( KnownColumn (Column name (Array chType))
, Deserializable chType
, TypeError ('Text "Arrays deserialization still unsupported")
)
=> SerializableColumn (Column name (Array chType)) where
{-# INLINE deserializeColumn #-}
deserializeColumn :: ProtocolRevision
-> Bool -> UVarInt -> Get (Column name (Array chType))
deserializeColumn ProtocolRevision
rev Bool
isCheckRequired UVarInt
_rows = do
forall column.
KnownColumn column =>
ProtocolRevision -> Bool -> Get ()
handleColumnHeader @(Column name (Array chType)) ProtocolRevision
rev Bool
isCheckRequired
(UInt64
arraySize, [UInt64]
_offsets) <- ProtocolRevision -> Get (UInt64, [UInt64])
readOffsets ProtocolRevision
rev
[chType]
_types <- Int -> Get chType -> Get [chType]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (UInt64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral UInt64
arraySize) (forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev)
Column
(GetColumnName (Column name (Array chType)))
(GetColumnType (Column name (Array chType)))
-> Get
(Column
(GetColumnName (Column name (Array chType)))
(GetColumnType (Column name (Array chType))))
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Column
(GetColumnName (Column name (Array chType)))
(GetColumnType (Column name (Array chType)))
-> Get
(Column
(GetColumnName (Column name (Array chType)))
(GetColumnType (Column name (Array chType)))))
-> Column
(GetColumnName (Column name (Array chType)))
(GetColumnType (Column name (Array chType)))
-> Get
(Column
(GetColumnName (Column name (Array chType)))
(GetColumnType (Column name (Array chType))))
forall a b. (a -> b) -> a -> b
$ forall column.
KnownColumn column =>
[GetColumnType column]
-> Column (GetColumnName column) (GetColumnType column)
mkColumn @(Column name (Array chType)) []
where
readOffsets :: ProtocolRevision -> Get (UInt64, [UInt64])
readOffsets :: ProtocolRevision -> Get (UInt64, [UInt64])
readOffsets ProtocolRevision
revivion = do
UInt64
size <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UInt64 ProtocolRevision
rev
(UInt64
size, ) ([UInt64] -> (UInt64, [UInt64]))
-> Get [UInt64] -> Get (UInt64, [UInt64])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UInt64 -> Get [UInt64]
go UInt64
size
where
go :: UInt64 -> Get [UInt64]
go UInt64
arraySize =
do
UInt64
nextOffset <- forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UInt64 ProtocolRevision
revivion
if UInt64
arraySize UInt64 -> UInt64 -> Bool
forall a. Ord a => a -> a -> Bool
>= UInt64
nextOffset
then [UInt64] -> Get [UInt64]
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [UInt64
nextOffset]
else (UInt64
nextOffset UInt64 -> [UInt64] -> [UInt64]
forall a. a -> [a] -> [a]
:) ([UInt64] -> [UInt64]) -> Get [UInt64] -> Get [UInt64]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UInt64 -> Get [UInt64]
go UInt64
arraySize
{-# INLINE serializeColumn #-}
serializeColumn :: ProtocolRevision -> Column name (Array chType) -> Builder
serializeColumn ProtocolRevision
_rev Column name (Array chType)
_column = Builder
forall a. HasCallStack => a
undefined
class
Deserializable chType
where
{-# INLINE deserialize #-}
default deserialize :: (Generic chType, GDeserial (Rep chType)) => ProtocolRevision -> Get chType
deserialize :: ProtocolRevision -> Get chType
deserialize ProtocolRevision
rev = Rep chType Any -> chType
forall a x. Generic a => Rep a x -> a
forall x. Rep chType x -> chType
to (Rep chType Any -> chType) -> Get (Rep chType Any) -> Get chType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get (Rep chType Any)
forall p. ProtocolRevision -> Get (Rep chType p)
forall (f :: * -> *) p.
GDeserial f =>
ProtocolRevision -> Get (f p)
gDeserialize ProtocolRevision
rev
class GDeserial f
where
gDeserialize :: ProtocolRevision -> Get (f p)
instance GDeserial f => GDeserial (D1 c (C1 c2 f))
where
gDeserialize :: forall p. ProtocolRevision -> Get (D1 c (C1 c2 f) p)
gDeserialize ProtocolRevision
rev = C1 c2 f p -> M1 D 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 -> M1 D c (C1 c2 f) p)
-> (f p -> C1 c2 f p) -> f p -> M1 D 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 -> M1 D c (C1 c2 f) p)
-> Get (f p) -> Get (M1 D c (C1 c2 f) p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ProtocolRevision -> Get (f p)
forall p. ProtocolRevision -> Get (f p)
forall (f :: * -> *) p.
GDeserial f =>
ProtocolRevision -> Get (f p)
gDeserialize ProtocolRevision
rev
{-# INLINE gDeserialize #-}
instance (GDeserial left, GDeserial right) => GDeserial (left :*: right) where
gDeserialize :: forall p. ProtocolRevision -> Get ((:*:) left right p)
gDeserialize ProtocolRevision
rev = (left p -> right p -> (:*:) left right p)
-> Get (left p) -> Get (right p) -> Get ((:*:) left right p)
forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 left p -> right p -> (:*:) left right p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (ProtocolRevision -> Get (left p)
forall p. ProtocolRevision -> Get (left p)
forall (f :: * -> *) p.
GDeserial f =>
ProtocolRevision -> Get (f p)
gDeserialize ProtocolRevision
rev) (ProtocolRevision -> Get (right p)
forall p. ProtocolRevision -> Get (right p)
forall (f :: * -> *) p.
GDeserial f =>
ProtocolRevision -> Get (f p)
gDeserialize ProtocolRevision
rev)
{-# INLINE gDeserialize #-}
instance {-# OVERLAPPING #-}
GDeserial right => GDeserial (S1 metaSel (Rec0 ProtocolRevision) :*: right) where
gDeserialize :: forall p.
ProtocolRevision
-> Get ((:*:) (S1 metaSel (Rec0 ProtocolRevision)) right p)
gDeserialize ProtocolRevision
rev = do
ProtocolRevision
chosenRev <- ProtocolRevision -> ProtocolRevision -> ProtocolRevision
forall a. Ord a => a -> a -> a
min ProtocolRevision
rev (ProtocolRevision -> ProtocolRevision)
-> (UVarInt -> ProtocolRevision) -> UVarInt -> ProtocolRevision
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UVarInt -> ProtocolRevision
forall a b. Coercible a b => a -> b
coerce (UVarInt -> ProtocolRevision)
-> Get UVarInt -> Get ProtocolRevision
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UVarInt ProtocolRevision
rev
(S1 metaSel (Rec0 ProtocolRevision) p
-> right p -> (:*:) (S1 metaSel (Rec0 ProtocolRevision)) right p)
-> Get (S1 metaSel (Rec0 ProtocolRevision) p)
-> Get (right p)
-> Get ((:*:) (S1 metaSel (Rec0 ProtocolRevision)) right p)
forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 S1 metaSel (Rec0 ProtocolRevision) p
-> right p -> (:*:) (S1 metaSel (Rec0 ProtocolRevision)) right p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) (S1 metaSel (Rec0 ProtocolRevision) p
-> Get (S1 metaSel (Rec0 ProtocolRevision) p)
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (S1 metaSel (Rec0 ProtocolRevision) p
-> Get (S1 metaSel (Rec0 ProtocolRevision) p))
-> (ProtocolRevision -> S1 metaSel (Rec0 ProtocolRevision) p)
-> ProtocolRevision
-> Get (S1 metaSel (Rec0 ProtocolRevision) p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rec0 ProtocolRevision p -> S1 metaSel (Rec0 ProtocolRevision) p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (Rec0 ProtocolRevision p -> S1 metaSel (Rec0 ProtocolRevision) p)
-> (ProtocolRevision -> Rec0 ProtocolRevision p)
-> ProtocolRevision
-> S1 metaSel (Rec0 ProtocolRevision) p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtocolRevision -> Rec0 ProtocolRevision p
forall k i c (p :: k). c -> K1 i c p
K1 (ProtocolRevision -> Get (S1 metaSel (Rec0 ProtocolRevision) p))
-> ProtocolRevision -> Get (S1 metaSel (Rec0 ProtocolRevision) p)
forall a b. (a -> b) -> a -> b
$ ProtocolRevision
chosenRev) (forall (f :: * -> *) p.
GDeserial f =>
ProtocolRevision -> Get (f p)
gDeserialize @right ProtocolRevision
chosenRev)
{-# INLINE gDeserialize #-}
instance
Deserializable chType
=>
GDeserial (S1 metaSel (Rec0 chType))
where
{-# INLINE gDeserialize #-}
gDeserialize :: forall p. ProtocolRevision -> Get (S1 metaSel (Rec0 chType) p)
gDeserialize ProtocolRevision
rev = Rec0 chType p -> M1 S metaSel (Rec0 chType) p
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (Rec0 chType p -> M1 S metaSel (Rec0 chType) p)
-> (chType -> Rec0 chType p)
-> chType
-> M1 S metaSel (Rec0 chType) p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. chType -> Rec0 chType p
forall k i c (p :: k). c -> K1 i c p
K1 (chType -> M1 S metaSel (Rec0 chType) p)
-> Get chType -> Get (M1 S metaSel (Rec0 chType) p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev
instance Deserializable Int8 where deserialize :: ProtocolRevision -> Get Int8
deserialize ProtocolRevision
_ = Int8 -> Int8
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Int8 -> Int8) -> Get Int8 -> Get Int8
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int8
getInt8; {-# INLINE deserialize #-}
instance Deserializable Int16 where deserialize :: ProtocolRevision -> Get Int16
deserialize ProtocolRevision
_ = Int16 -> Int16
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Int16 -> Int16) -> Get Int16 -> Get Int16
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int16
getInt16le; {-# INLINE deserialize #-}
instance Deserializable Int32 where deserialize :: ProtocolRevision -> Get Int32
deserialize ProtocolRevision
_ = Int32 -> Int32
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Int32 -> Int32) -> Get Int32 -> Get Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int32
getInt32le; {-# INLINE deserialize #-}
instance Deserializable Int64 where deserialize :: ProtocolRevision -> Get Int64
deserialize ProtocolRevision
_ = Int64 -> Int64
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Int64 -> Int64) -> Get Int64 -> Get Int64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int64
getInt64le; {-# INLINE deserialize #-}
instance Deserializable Int128 where deserialize :: ProtocolRevision -> Get Int128
deserialize ProtocolRevision
_ = Int128 -> Int128
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (Int128 -> Int128) -> Get Int128 -> Get Int128
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (UInt64 -> UInt64 -> Int128)
-> Get UInt64 -> Get UInt64 -> Get Int128
forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((UInt64 -> UInt64 -> Int128) -> UInt64 -> UInt64 -> Int128
forall a b c. (a -> b -> c) -> b -> a -> c
flip UInt64 -> UInt64 -> Int128
Int128) Get UInt64
getWord64le Get UInt64
getWord64le; {-# INLINE deserialize #-}
instance Deserializable UInt8 where deserialize :: ProtocolRevision -> Get UInt8
deserialize ProtocolRevision
_ = UInt8 -> UInt8
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt8 -> UInt8) -> Get UInt8 -> Get UInt8
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt8
getWord8; {-# INLINE deserialize #-}
instance Deserializable UInt16 where deserialize :: ProtocolRevision -> Get UInt16
deserialize ProtocolRevision
_ = UInt16 -> UInt16
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt16 -> UInt16) -> Get UInt16 -> Get UInt16
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt16
getWord16le; {-# INLINE deserialize #-}
instance Deserializable UInt32 where deserialize :: ProtocolRevision -> Get UInt32
deserialize ProtocolRevision
_ = UInt32 -> UInt32
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt32 -> UInt32) -> Get UInt32 -> Get UInt32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt32
getWord32le; {-# INLINE deserialize #-}
instance Deserializable UInt64 where deserialize :: ProtocolRevision -> Get UInt64
deserialize ProtocolRevision
_ = UInt64 -> UInt64
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt64 -> UInt64) -> Get UInt64 -> Get UInt64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt64
getWord64le; {-# INLINE deserialize #-}
instance Deserializable UInt128 where deserialize :: ProtocolRevision -> Get UInt128
deserialize ProtocolRevision
_ = UInt128 -> UInt128
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt128 -> UInt128) -> Get UInt128 -> Get UInt128
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (UInt64 -> UInt64 -> UInt128)
-> Get UInt64 -> Get UInt64 -> Get UInt128
forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((UInt64 -> UInt64 -> UInt128) -> UInt64 -> UInt64 -> UInt128
forall a b c. (a -> b -> c) -> b -> a -> c
flip UInt64 -> UInt64 -> UInt128
Word128) Get UInt64
getWord64le Get UInt64
getWord64le; {-# INLINE deserialize #-}
instance Deserializable UUID where deserialize :: ProtocolRevision -> Get UUID
deserialize ProtocolRevision
_ = UInt128 -> UUID
MkChUUID (UInt128 -> UUID) -> Get UInt128 -> Get UUID
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (UInt64 -> UInt64 -> UInt128)
-> Get UInt64 -> Get UInt64 -> Get UInt128
forall a b c. (a -> b -> c) -> Get a -> Get b -> Get c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((UInt64 -> UInt64 -> UInt128) -> UInt64 -> UInt64 -> UInt128
forall a b c. (a -> b -> c) -> b -> a -> c
flip UInt64 -> UInt64 -> UInt128
Word128) Get UInt64
getWord64le Get UInt64
getWord64le; {-# INLINE deserialize #-}
instance Deserializable Date where deserialize :: ProtocolRevision -> Get Date
deserialize ProtocolRevision
_ = UInt16 -> Date
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt16 -> Date) -> Get UInt16 -> Get Date
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt16
getWord16le; {-# INLINE deserialize #-}
instance Deserializable (DateTime tz) where deserialize :: ProtocolRevision -> Get (DateTime tz)
deserialize ProtocolRevision
_ = UInt32 -> DateTime tz
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt32 -> DateTime tz) -> Get UInt32 -> Get (DateTime tz)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt32
getWord32le; {-# INLINE deserialize #-}
instance Deserializable (DateTime64 precision tz) where deserialize :: ProtocolRevision -> Get (DateTime64 precision tz)
deserialize ProtocolRevision
_ = UInt64 -> DateTime64 precision tz
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (UInt64 -> DateTime64 precision tz)
-> Get UInt64 -> Get (DateTime64 precision tz)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get UInt64
getWord64le; {-# INLINE deserialize #-}
instance Deserializable ChString where
{-# INLINE deserialize #-}
deserialize :: ProtocolRevision -> Get ChString
deserialize = (\Int
n -> ByteString -> ChString
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType (ByteString -> ChString) -> Get ByteString -> Get ChString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> (ByteString -> ByteString) -> Get ByteString
forall a. Int -> (ByteString -> a) -> Get a
readN Int
n (Int -> ByteString -> ByteString
BS.take Int
n)) (Int -> Get ChString)
-> (UVarInt -> Int) -> UVarInt -> Get ChString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UVarInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (UVarInt -> Get ChString)
-> (ProtocolRevision -> Get UVarInt)
-> ProtocolRevision
-> Get ChString
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @UVarInt
instance Deserializable UVarInt where
{-# INLINE deserialize #-}
deserialize :: ProtocolRevision -> Get UVarInt
deserialize ProtocolRevision
_ = Int -> UVarInt -> Get UVarInt
forall {a}. (Bits a, Num a) => Int -> a -> Get a
go Int
0 (UVarInt
0 :: UVarInt)
where
go :: Int -> a -> Get a
go Int
i a
o | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 = do
UInt8
byte <- Get UInt8
getWord8
let o' :: a
o' = a
o a -> a -> a
forall a. Bits a => a -> a -> a
.|. ((UInt8 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral UInt8
byte a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0x7f) a -> Int -> a
forall a. Bits a => a -> Int -> a
`unsafeShiftL` (Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
i))
if UInt8
byte UInt8 -> UInt8 -> UInt8
forall a. Bits a => a -> a -> a
.&. UInt8
0x80 UInt8 -> UInt8 -> Bool
forall a. Eq a => a -> a -> Bool
== UInt8
0 then a -> Get a
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Get a) -> a -> Get a
forall a b. (a -> b) -> a -> b
$! a
o' else Int -> a -> Get a
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (a -> Get a) -> a -> Get a
forall a b. (a -> b) -> a -> b
$! a
o'
go Int
_ a
_ = String -> Get a
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"input exceeds varuint size"
class FromChType chType outputType where fromChType :: chType -> outputType
instance FromChType UUID (Word64, Word64) where fromChType :: UUID -> (UInt64, UInt64)
fromChType (MkChUUID (Word128 UInt64
w64hi UInt64
w64lo)) = (UInt64
w64hi, UInt64
w64lo)
instance {-# OVERLAPPABLE #-} (IsChType chType, chType ~ inputType) => FromChType chType inputType where fromChType :: chType -> inputType
fromChType = chType -> chType
chType -> inputType
forall a. a -> a
id
instance FromChType (DateTime tz) Word32 where fromChType :: DateTime tz -> UInt32
fromChType = DateTime tz -> UInt32
forall a b. Coercible a b => a -> b
coerce
instance FromChType (DateTime tz) UTCTime where fromChType :: DateTime tz -> UTCTime
fromChType (MkDateTime UInt32
w32) = POSIXTime -> UTCTime
posixSecondsToUTCTime (UInt32 -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral UInt32
w32)
instance FromChType (DateTime64 precision tz) Word64 where fromChType :: DateTime64 precision tz -> UInt64
fromChType = DateTime64 precision tz -> UInt64
forall a b. Coercible a b => a -> b
coerce
instance
FromChType chType inputType
=>
FromChType (Nullable chType) (Nullable inputType)
where
fromChType :: Nullable chType -> Nullable inputType
fromChType = (chType -> inputType) -> Nullable chType -> Nullable inputType
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType @chType)
instance FromChType chType (LowCardinality chType) where
fromChType :: chType -> LowCardinality chType
fromChType = chType -> LowCardinality chType
forall chType. chType -> LowCardinality chType
MkLowCardinality
instance FromChType Date Word16 where fromChType :: Date -> UInt16
fromChType = Date -> UInt16
forall a b. Coercible a b => a -> b
coerce
instance
FromChType chType outputType
=>
FromChType (LowCardinality chType) outputType
where
fromChType :: LowCardinality chType -> outputType
fromChType (MkLowCardinality chType
value) = chType -> outputType
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType chType
value
instance FromChType ChString BS.ByteString where fromChType :: ChString -> ByteString
fromChType (MkChString ByteString
string) = ByteString
string
instance FromChType ChString Builder where fromChType :: ChString -> Builder
fromChType (MkChString ByteString
string) = ByteString -> Builder
byteString ByteString
string
instance
( TypeError
( 'Text "ChString to Text using FromChType convertion could cause exception"
':$$: 'Text "Decode ByteString manually if you are sure it's always can be decoded or replace it with ByteString"
)
) =>
FromChType ChString Text
where
fromChType :: ChString -> Text
fromChType = String -> ChString -> Text
forall a. HasCallStack => String -> a
error String
"Unreachable"
instance FromChType chType inputType => FromChType (Array chType) [inputType]
where
fromChType :: Array chType -> [inputType]
fromChType (MkChArray [chType]
values) = (chType -> inputType) -> [chType] -> [inputType]
forall a b. (a -> b) -> [a] -> [b]
map chType -> inputType
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType [chType]
values
data Column (name :: Symbol) (chType :: Type) where
UInt8Column :: [UInt8] -> Column name UInt8; Int8Column :: [Int8] -> Column name Int8
UInt16Column :: [UInt16] -> Column name UInt16; Int16Column :: [Int16] -> Column name Int16
UInt32Column :: [UInt32] -> Column name UInt32; Int32Column :: [Int32] -> Column name Int32
UInt64Column :: [UInt64] -> Column name UInt64; Int64Column :: [Int64] -> Column name Int64
UInt128Column :: [UInt128] -> Column name UInt128; Int128Column :: [Int128] -> Column name Int128
DateTimeColumn :: [DateTime tz] -> Column name (DateTime tz)
DateTime64Column :: [DateTime64 precision tz] -> Column name (DateTime64 precision tz)
DateColumn :: [Date] -> Column name Date
UUIDColumn :: [UUID] -> Column name UUID
StringColumn :: [ChString] -> Column name ChString
ArrayColumn :: [Array chType] -> Column name (Array chType)
NullableColumn :: [Nullable chType] -> Column name (Nullable chType)
LowCardinalityColumn :: IsLowCardinalitySupported chType => [chType] -> Column name (LowCardinality chType)
type family GetColumnName column :: Symbol where GetColumnName (Column name columnType) = name
type family GetColumnType column :: Type where GetColumnType (Column name columnType) = columnType
{-# INLINE [0] columnValues #-}
columnValues :: Column name chType -> [chType]
columnValues :: forall (name :: Symbol) chType. Column name chType -> [chType]
columnValues Column name chType
column = case Column name chType
column of
(UInt8Column [UInt8]
values) -> [chType]
[UInt8]
values; (UInt16Column [UInt16]
values) -> [chType]
[UInt16]
values
(UInt32Column [UInt32]
values) -> [chType]
[UInt32]
values; (UInt64Column [UInt64]
values) -> [chType]
[UInt64]
values
(UInt128Column [UInt128]
values) -> [chType]
[UInt128]
values; (Int8Column [Int8]
values) -> [chType]
[Int8]
values
(Int16Column [Int16]
values) -> [chType]
[Int16]
values; (Int32Column [Int32]
values) -> [chType]
[Int32]
values
(Int64Column [Int64]
values) -> [chType]
[Int64]
values; (Int128Column [Int128]
values) -> [chType]
[Int128]
values
(DateColumn [Date]
values) -> [chType]
[Date]
values; (DateTimeColumn [DateTime tz]
values) -> [chType]
[DateTime tz]
values; (DateTime64Column [DateTime64 precision tz]
values) -> [chType]
[DateTime64 precision tz]
values;
(UUIDColumn [UUID]
values) -> [chType]
[UUID]
values; (StringColumn [ChString]
values) -> [chType]
[ChString]
values
(ArrayColumn [Array chType]
values) -> [chType]
[Array chType]
values; (NullableColumn [Maybe chType]
values) -> [chType]
[Maybe chType]
values
(LowCardinalityColumn [chType]
values) -> (chType -> chType) -> [chType] -> [chType]
forall a b. (a -> b) -> [a] -> [b]
map chType -> chType
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType [chType]
values
class
( IsChType (GetColumnType column)
, KnownSymbol (GetColumnName column)
) =>
KnownColumn column where
renderColumnName :: Builder
renderColumnName = (String -> Builder
stringUtf8 (String -> Builder)
-> (Proxy (GetColumnName column) -> String)
-> Proxy (GetColumnName column)
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(GetColumnName column)) Proxy (GetColumnName column)
forall {k} (t :: k). Proxy t
Proxy
renderColumnType :: Builder
renderColumnType = ByteString -> Builder
byteString (ByteString -> Builder)
-> (String -> ByteString) -> String -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> Builder) -> String -> Builder
forall a b. (a -> b) -> a -> b
$ forall chType. IsChType chType => String
chTypeName @(GetColumnType column)
mkColumn :: [GetColumnType column] -> Column (GetColumnName column) (GetColumnType column)
instance KnownSymbol name => KnownColumn (Column name UInt8) where mkColumn :: [GetColumnType (Column name UInt8)]
-> Column
(GetColumnName (Column name UInt8))
(GetColumnType (Column name UInt8))
mkColumn = [UInt8] -> Column name UInt8
[GetColumnType (Column name UInt8)]
-> Column
(GetColumnName (Column name UInt8))
(GetColumnType (Column name UInt8))
forall (name :: Symbol). [UInt8] -> Column name UInt8
UInt8Column
instance KnownSymbol name => KnownColumn (Column name UInt16) where mkColumn :: [GetColumnType (Column name UInt16)]
-> Column
(GetColumnName (Column name UInt16))
(GetColumnType (Column name UInt16))
mkColumn = [UInt16] -> Column name UInt16
[GetColumnType (Column name UInt16)]
-> Column
(GetColumnName (Column name UInt16))
(GetColumnType (Column name UInt16))
forall (name :: Symbol). [UInt16] -> Column name UInt16
UInt16Column
instance KnownSymbol name => KnownColumn (Column name UInt32) where mkColumn :: [GetColumnType (Column name UInt32)]
-> Column
(GetColumnName (Column name UInt32))
(GetColumnType (Column name UInt32))
mkColumn = [UInt32] -> Column name UInt32
[GetColumnType (Column name UInt32)]
-> Column
(GetColumnName (Column name UInt32))
(GetColumnType (Column name UInt32))
forall (name :: Symbol). [UInt32] -> Column name UInt32
UInt32Column
instance KnownSymbol name => KnownColumn (Column name UInt64) where mkColumn :: [GetColumnType (Column name UInt64)]
-> Column
(GetColumnName (Column name UInt64))
(GetColumnType (Column name UInt64))
mkColumn = [UInt64] -> Column name UInt64
[GetColumnType (Column name UInt64)]
-> Column
(GetColumnName (Column name UInt64))
(GetColumnType (Column name UInt64))
forall (name :: Symbol). [UInt64] -> Column name UInt64
UInt64Column
instance KnownSymbol name => KnownColumn (Column name UInt128) where mkColumn :: [GetColumnType (Column name UInt128)]
-> Column
(GetColumnName (Column name UInt128))
(GetColumnType (Column name UInt128))
mkColumn = [UInt128] -> Column name UInt128
[GetColumnType (Column name UInt128)]
-> Column
(GetColumnName (Column name UInt128))
(GetColumnType (Column name UInt128))
forall (name :: Symbol). [UInt128] -> Column name UInt128
UInt128Column
instance KnownSymbol name => KnownColumn (Column name Int8) where mkColumn :: [GetColumnType (Column name Int8)]
-> Column
(GetColumnName (Column name Int8))
(GetColumnType (Column name Int8))
mkColumn = [Int8] -> Column name Int8
[GetColumnType (Column name Int8)]
-> Column
(GetColumnName (Column name Int8))
(GetColumnType (Column name Int8))
forall (name :: Symbol). [Int8] -> Column name Int8
Int8Column
instance KnownSymbol name => KnownColumn (Column name Int16) where mkColumn :: [GetColumnType (Column name Int16)]
-> Column
(GetColumnName (Column name Int16))
(GetColumnType (Column name Int16))
mkColumn = [Int16] -> Column name Int16
[GetColumnType (Column name Int16)]
-> Column
(GetColumnName (Column name Int16))
(GetColumnType (Column name Int16))
forall (name :: Symbol). [Int16] -> Column name Int16
Int16Column
instance KnownSymbol name => KnownColumn (Column name Int32) where mkColumn :: [GetColumnType (Column name Int32)]
-> Column
(GetColumnName (Column name Int32))
(GetColumnType (Column name Int32))
mkColumn = [Int32] -> Column name Int32
[GetColumnType (Column name Int32)]
-> Column
(GetColumnName (Column name Int32))
(GetColumnType (Column name Int32))
forall (name :: Symbol). [Int32] -> Column name Int32
Int32Column
instance KnownSymbol name => KnownColumn (Column name Int64) where mkColumn :: [GetColumnType (Column name Int64)]
-> Column
(GetColumnName (Column name Int64))
(GetColumnType (Column name Int64))
mkColumn = [Int64] -> Column name Int64
[GetColumnType (Column name Int64)]
-> Column
(GetColumnName (Column name Int64))
(GetColumnType (Column name Int64))
forall (name :: Symbol). [Int64] -> Column name Int64
Int64Column
instance KnownSymbol name => KnownColumn (Column name Int128) where mkColumn :: [GetColumnType (Column name Int128)]
-> Column
(GetColumnName (Column name Int128))
(GetColumnType (Column name Int128))
mkColumn = [Int128] -> Column name Int128
[GetColumnType (Column name Int128)]
-> Column
(GetColumnName (Column name Int128))
(GetColumnType (Column name Int128))
forall (name :: Symbol). [Int128] -> Column name Int128
Int128Column
instance KnownSymbol name => KnownColumn (Column name Date) where mkColumn :: [GetColumnType (Column name Date)]
-> Column
(GetColumnName (Column name Date))
(GetColumnType (Column name Date))
mkColumn = [Date] -> Column name Date
[GetColumnType (Column name Date)]
-> Column
(GetColumnName (Column name Date))
(GetColumnType (Column name Date))
forall (name :: Symbol). [Date] -> Column name Date
DateColumn
instance
( KnownSymbol name
, IsChType (DateTime tz)
) =>
KnownColumn (Column name (DateTime tz)) where mkColumn :: [GetColumnType (Column name (DateTime tz))]
-> Column
(GetColumnName (Column name (DateTime tz)))
(GetColumnType (Column name (DateTime tz)))
mkColumn = [DateTime tz] -> Column name (DateTime tz)
[GetColumnType (Column name (DateTime tz))]
-> Column
(GetColumnName (Column name (DateTime tz)))
(GetColumnType (Column name (DateTime tz)))
forall (name :: Symbol) (name :: Symbol).
[DateTime name] -> Column name (DateTime name)
DateTimeColumn
instance
( KnownSymbol name
, IsChType (DateTime64 precision tz)
) =>
KnownColumn (Column name (DateTime64 precision tz)) where mkColumn :: [GetColumnType (Column name (DateTime64 precision tz))]
-> Column
(GetColumnName (Column name (DateTime64 precision tz)))
(GetColumnType (Column name (DateTime64 precision tz)))
mkColumn = [DateTime64 precision tz] -> Column name (DateTime64 precision tz)
[GetColumnType (Column name (DateTime64 precision tz))]
-> Column
(GetColumnName (Column name (DateTime64 precision tz)))
(GetColumnType (Column name (DateTime64 precision tz)))
forall (name :: Nat) (chType :: Symbol) (name :: Symbol).
[DateTime64 name chType] -> Column name (DateTime64 name chType)
DateTime64Column
instance KnownSymbol name => KnownColumn (Column name UUID) where mkColumn :: [GetColumnType (Column name UUID)]
-> Column
(GetColumnName (Column name UUID))
(GetColumnType (Column name UUID))
mkColumn = [UUID] -> Column name UUID
[GetColumnType (Column name UUID)]
-> Column
(GetColumnName (Column name UUID))
(GetColumnType (Column name UUID))
forall (name :: Symbol). [UUID] -> Column name UUID
UUIDColumn
instance
( KnownSymbol name
, IsChType chType
, IsChType (Nullable chType)
) =>
KnownColumn (Column name (Nullable chType)) where mkColumn :: [GetColumnType (Column name (Nullable chType))]
-> Column
(GetColumnName (Column name (Nullable chType)))
(GetColumnType (Column name (Nullable chType)))
mkColumn = [Nullable chType] -> Column name (Nullable chType)
[GetColumnType (Column name (Nullable chType))]
-> Column
(GetColumnName (Column name (Nullable chType)))
(GetColumnType (Column name (Nullable chType)))
forall name (name :: Symbol).
[Nullable name] -> Column name (Nullable name)
NullableColumn
instance KnownSymbol name => KnownColumn (Column name ChString) where mkColumn :: [GetColumnType (Column name ChString)]
-> Column
(GetColumnName (Column name ChString))
(GetColumnType (Column name ChString))
mkColumn = [ChString] -> Column name ChString
[GetColumnType (Column name ChString)]
-> Column
(GetColumnName (Column name ChString))
(GetColumnType (Column name ChString))
forall (name :: Symbol). [ChString] -> Column name ChString
StringColumn
instance
( KnownSymbol name
, IsChType (LowCardinality chType)
, IsLowCardinalitySupported chType
) =>
KnownColumn (Column name (LowCardinality chType)) where mkColumn :: [GetColumnType (Column name (LowCardinality chType))]
-> Column
(GetColumnName (Column name (LowCardinality chType)))
(GetColumnType (Column name (LowCardinality chType)))
mkColumn = [chType] -> Column name (LowCardinality chType)
forall name (name :: Symbol).
IsLowCardinalitySupported name =>
[name] -> Column name (LowCardinality name)
LowCardinalityColumn ([chType] -> Column name (LowCardinality chType))
-> ([LowCardinality chType] -> [chType])
-> [LowCardinality chType]
-> Column name (LowCardinality chType)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LowCardinality chType -> chType)
-> [LowCardinality chType] -> [chType]
forall a b. (a -> b) -> [a] -> [b]
map LowCardinality chType -> chType
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance KnownSymbol name => KnownColumn (Column name (Array ChString)) where mkColumn :: [GetColumnType (Column name (Array ChString))]
-> Column
(GetColumnName (Column name (Array ChString)))
(GetColumnType (Column name (Array ChString)))
mkColumn = [Array ChString] -> Column name (Array ChString)
[GetColumnType (Column name (Array ChString))]
-> Column
(GetColumnName (Column name (Array ChString)))
(GetColumnType (Column name (Array ChString)))
forall name (name :: Symbol).
[Array name] -> Column name (Array name)
ArrayColumn
type family KnownParameter param
where
KnownParameter (Parameter name parType) = (KnownSymbol name, IsChType parType, ToQueryPart parType)
data Parameter (name :: Symbol) (chType :: Type) = MkParamater chType
data Parameters parameters where
NoParameters :: Parameters '[]
AddParameter
:: KnownParameter (Parameter name chType)
=> Parameter name chType
-> Parameters parameters
-> Parameters (Parameter name chType ': parameters)
viewParameters :: (Parameters '[] -> Parameters passedParameters) -> Builder
viewParameters :: forall (passedParameters :: [*]).
(Parameters '[] -> Parameters passedParameters) -> Builder
viewParameters Parameters '[] -> Parameters passedParameters
interpreter = Builder
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Parameters passedParameters -> Builder
forall (params :: [*]). Parameters params -> Builder
renderParameters (Parameters '[] -> Parameters passedParameters
interpreter Parameters '[]
NoParameters) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
")"
renderParameters :: Parameters params -> Builder
renderParameters :: forall (params :: [*]). Parameters params -> Builder
renderParameters Parameters params
NoParameters = Builder
""
renderParameters (AddParameter Parameter name chType
param Parameters parameters
NoParameters) = Parameter name chType -> Builder
forall (name :: Symbol) chType.
KnownParameter (Parameter name chType) =>
Parameter name chType -> Builder
renderParameter Parameter name chType
param
renderParameters (AddParameter Parameter name chType
param Parameters parameters
moreParams) = Parameter name chType -> Builder
forall (name :: Symbol) chType.
KnownParameter (Parameter name chType) =>
Parameter name chType -> Builder
renderParameter Parameter name chType
param Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
", " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Parameters parameters -> Builder
forall (params :: [*]). Parameters params -> Builder
renderParameters Parameters parameters
moreParams
parameter
:: forall name chType parameters userType
. (ToChType chType userType, KnownParameter (Parameter name chType))
=> userType -> Parameters parameters -> Parameters (Parameter name chType ': parameters)
parameter :: forall (name :: Symbol) chType (parameters :: [*]) userType.
(ToChType chType userType,
KnownParameter (Parameter name chType)) =>
userType
-> Parameters parameters
-> Parameters (Parameter name chType : parameters)
parameter userType
val = Parameter name chType
-> Parameters parameters
-> Parameters (Parameter name chType : parameters)
forall (name :: Symbol) chType (parameters :: [*]).
KnownParameter (Parameter name chType) =>
Parameter name chType
-> Parameters parameters
-> Parameters (Parameter name chType : parameters)
AddParameter (chType -> Parameter name chType
forall (name :: Symbol) chType. chType -> Parameter name chType
MkParamater (chType -> Parameter name chType)
-> chType -> Parameter name chType
forall a b. (a -> b) -> a -> b
$ userType -> chType
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType userType
val)
renderParameter :: forall name chType . KnownParameter (Parameter name chType) => Parameter name chType -> Builder
renderParameter :: forall (name :: Symbol) chType.
KnownParameter (Parameter name chType) =>
Parameter name chType -> Builder
renderParameter (MkParamater chType
chType) = (ByteString -> Builder
byteString (ByteString -> Builder)
-> (Proxy name -> ByteString) -> Proxy name -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (Proxy name -> String) -> Proxy name -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @name) Proxy name
forall {k} (t :: k). Proxy t
Proxy Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"=" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> chType -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart chType
chType
class ToQueryPart chType where toQueryPart :: chType -> BS.Builder
instance ToQueryPart Int8 where toQueryPart :: Int8 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder) -> (Int8 -> ByteString) -> Int8 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString) -> (Int8 -> String) -> Int8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> String
forall a. Show a => a -> String
show
instance ToQueryPart Int16 where toQueryPart :: Int16 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (Int16 -> ByteString) -> Int16 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString) -> (Int16 -> String) -> Int16 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> String
forall a. Show a => a -> String
show
instance ToQueryPart Int32 where toQueryPart :: Int32 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (Int32 -> ByteString) -> Int32 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString) -> (Int32 -> String) -> Int32 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> String
forall a. Show a => a -> String
show
instance ToQueryPart Int64 where toQueryPart :: Int64 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (Int64 -> ByteString) -> Int64 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString) -> (Int64 -> String) -> Int64 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> String
forall a. Show a => a -> String
show
instance ToQueryPart Int128 where toQueryPart :: Int128 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (Int128 -> ByteString) -> Int128 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (Int128 -> String) -> Int128 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int128 -> String
forall a. Show a => a -> String
show
instance ToQueryPart UInt8 where toQueryPart :: UInt8 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (UInt8 -> ByteString) -> UInt8 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString) -> (UInt8 -> String) -> UInt8 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt8 -> String
forall a. Show a => a -> String
show
instance ToQueryPart UInt16 where toQueryPart :: UInt16 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (UInt16 -> ByteString) -> UInt16 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (UInt16 -> String) -> UInt16 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt16 -> String
forall a. Show a => a -> String
show
instance ToQueryPart UInt32 where toQueryPart :: UInt32 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (UInt32 -> ByteString) -> UInt32 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (UInt32 -> String) -> UInt32 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt32 -> String
forall a. Show a => a -> String
show
instance ToQueryPart UInt64 where toQueryPart :: UInt64 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (UInt64 -> ByteString) -> UInt64 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (UInt64 -> String) -> UInt64 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt64 -> String
forall a. Show a => a -> String
show
instance ToQueryPart UInt128 where toQueryPart :: UInt128 -> Builder
toQueryPart = ByteString -> Builder
byteString (ByteString -> Builder)
-> (UInt128 -> ByteString) -> UInt128 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString)
-> (UInt128 -> String) -> UInt128 -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt128 -> String
forall a. Show a => a -> String
show
instance ToQueryPart chType => ToQueryPart (Nullable chType)
where
toQueryPart :: Nullable chType -> Builder
toQueryPart = Builder -> (chType -> Builder) -> Nullable chType -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"null" chType -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart
instance ToQueryPart chType => ToQueryPart (LowCardinality chType)
where
toQueryPart :: LowCardinality chType -> Builder
toQueryPart (MkLowCardinality chType
chType) = chType -> Builder
forall chType. ToQueryPart chType => chType -> Builder
toQueryPart chType
chType
instance ToQueryPart UUID where
toQueryPart :: UUID -> Builder
toQueryPart (MkChUUID (Word128 UInt64
hi UInt64
lo)) = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat
[Builder
"'", Int -> UInt64 -> Builder
p Int
3 UInt64
hi, Int -> UInt64 -> Builder
p Int
2 UInt64
hi, Builder
"-", Int -> UInt64 -> Builder
p Int
1 UInt64
hi, Builder
"-", Int -> UInt64 -> Builder
p Int
0 UInt64
hi, Builder
"-", Int -> UInt64 -> Builder
p Int
3 UInt64
lo, Builder
"-", Int -> UInt64 -> Builder
p Int
2 UInt64
lo, Int -> UInt64 -> Builder
p Int
1 UInt64
lo, Int -> UInt64 -> Builder
p Int
0 UInt64
lo, Builder
"'"]
where
p :: Int -> Word64 -> Builder
p :: Int -> UInt64 -> Builder
p Int
shiftN UInt64
word = UInt16 -> Builder
word16HexFixed (UInt16 -> Builder) -> UInt16 -> Builder
forall a b. (a -> b) -> a -> b
$ UInt64 -> UInt16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (UInt64
word UInt64 -> Int -> UInt64
forall a. Bits a => a -> Int -> a
`unsafeShiftR` (Int
shiftNInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
16))
instance ToQueryPart ChString where
toQueryPart :: ChString -> Builder
toQueryPart (MkChString ByteString
string) = Builder
"'" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
escapeQuery ByteString
string Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"'"
where
escapeQuery :: BS.ByteString -> Builder
escapeQuery :: ByteString -> Builder
escapeQuery = ByteString -> Builder
byteString (ByteString -> Builder)
-> (ByteString -> ByteString) -> ByteString -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> ByteString) -> ByteString -> ByteString
BS8.concatMap (\case Char
'\'' -> ByteString
"\\\'"; Char
'\\' -> ByteString
"\\\\"; Char
sym -> Char -> ByteString
singleton Char
sym;)
instance ToQueryPart (DateTime tz)
where
toQueryPart :: DateTime tz -> Builder
toQueryPart DateTime tz
chDateTime = let time :: ByteString
time = String -> ByteString
BS8.pack (String -> ByteString)
-> (DateTime tz -> String) -> DateTime tz -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt32 -> String
forall a. Show a => a -> String
show (UInt32 -> String)
-> (DateTime tz -> UInt32) -> DateTime tz -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType @(DateTime tz) @Word32 (DateTime tz -> ByteString) -> DateTime tz -> ByteString
forall a b. (a -> b) -> a -> b
$ DateTime tz
chDateTime
in ByteString -> Builder
byteString (Int -> Char -> ByteString
BS8.replicate (Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
- ByteString -> Int
BS8.length ByteString
time) Char
'0' ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
time)
instance (IsChType chType, ToQueryPart chType) => ToQueryPart (Array chType)
where
toQueryPart :: Array chType -> Builder
toQueryPart
= (\Builder
x -> Builder
"[" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"]")
(Builder -> Builder)
-> (Array chType -> Builder) -> Array chType -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder
-> ((Builder, [Builder]) -> Builder)
-> Maybe (Builder, [Builder])
-> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
"" ((Builder -> [Builder] -> Builder)
-> (Builder, [Builder]) -> Builder
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Builder -> Builder -> Builder) -> Builder -> [Builder] -> Builder
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\Builder
a Builder
b -> Builder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"," Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b))) (Maybe (Builder, [Builder]) -> Builder)
-> ([chType] -> Maybe (Builder, [Builder])) -> [chType] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Builder] -> Maybe (Builder, [Builder])
forall a. [a] -> Maybe (a, [a])
uncons
([Builder] -> Maybe (Builder, [Builder]))
-> ([chType] -> [Builder])
-> [chType]
-> Maybe (Builder, [Builder])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (chType -> Builder) -> [chType] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (forall chType. ToQueryPart chType => chType -> Builder
toQueryPart @chType)) ([chType] -> Builder)
-> (Array chType -> [chType]) -> Array chType -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType @(Array chType) @[chType]
class Serializable chType
where
default serialize :: (Generic chType, GSerial (Rep chType)) => ProtocolRevision -> chType -> Builder
serialize :: ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev = ProtocolRevision -> Rep chType Any -> Builder
forall p. ProtocolRevision -> Rep chType p -> Builder
forall (f :: * -> *) p.
GSerial f =>
ProtocolRevision -> f p -> Builder
gSerialize ProtocolRevision
rev (Rep chType Any -> Builder)
-> (chType -> Rep chType Any) -> chType -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. chType -> Rep chType Any
forall x. chType -> Rep chType x
forall a x. Generic a => a -> Rep a x
from
instance Serializable UVarInt where
serialize :: ProtocolRevision -> UVarInt -> Builder
serialize ProtocolRevision
_ = UVarInt -> Builder
forall {t}. (Integral t, Bits t) => t -> Builder
go
where
go :: t -> Builder
go t
i
| t
i t -> t -> Bool
forall a. Ord a => a -> a -> Bool
< t
0x80 = UInt8 -> Builder
word8 (t -> UInt8
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
i)
| Bool
otherwise = UInt8 -> Builder
word8 (UInt8 -> Int -> UInt8
forall a. Bits a => a -> Int -> a
setBit (t -> UInt8
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
i) Int
7) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> t -> Builder
go (t
i t -> Int -> t
forall a. Bits a => a -> Int -> a
`unsafeShiftR` Int
7)
instance Serializable ChString where
serialize :: ProtocolRevision -> ChString -> Builder
serialize ProtocolRevision
rev ChString
str = (forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize @UVarInt ProtocolRevision
rev (UVarInt -> Builder)
-> (ChString -> UVarInt) -> ChString -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> UVarInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> UVarInt) -> (ChString -> Int) -> ChString -> UVarInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int
BS.length (ByteString -> Int) -> (ChString -> ByteString) -> ChString -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ChString -> ByteString
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType) ChString
str Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ChString -> Builder
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType ChString
str
instance Serializable UUID where serialize :: ProtocolRevision -> UUID -> Builder
serialize ProtocolRevision
_ = (\(UInt64
hi, UInt64
lo) -> UInt64 -> Builder
word64LE UInt64
lo Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> UInt64 -> Builder
word64LE UInt64
hi) ((UInt64, UInt64) -> Builder)
-> (UUID -> (UInt64, UInt64)) -> UUID -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> (UInt64, UInt64)
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable Int8 where serialize :: ProtocolRevision -> Int8 -> Builder
serialize ProtocolRevision
_ = Int8 -> Builder
int8 (Int8 -> Builder) -> (Int8 -> Int8) -> Int8 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int8
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable Int16 where serialize :: ProtocolRevision -> Int16 -> Builder
serialize ProtocolRevision
_ = Int16 -> Builder
int16LE (Int16 -> Builder) -> (Int16 -> Int16) -> Int16 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int16
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable Int32 where serialize :: ProtocolRevision -> Int32 -> Builder
serialize ProtocolRevision
_ = Int32 -> Builder
int32LE (Int32 -> Builder) -> (Int32 -> Int32) -> Int32 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int32
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable Int64 where serialize :: ProtocolRevision -> Int64 -> Builder
serialize ProtocolRevision
_ = Int64 -> Builder
int64LE (Int64 -> Builder) -> (Int64 -> Int64) -> Int64 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Int64
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable Int128 where serialize :: ProtocolRevision -> Int128 -> Builder
serialize ProtocolRevision
_ = (\(Int128 UInt64
hi UInt64
lo) -> UInt64 -> Builder
word64LE UInt64
lo Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> UInt64 -> Builder
word64LE UInt64
hi) (Int128 -> Builder) -> (Int128 -> Int128) -> Int128 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int128 -> Int128
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable UInt8 where serialize :: ProtocolRevision -> UInt8 -> Builder
serialize ProtocolRevision
_ = UInt8 -> Builder
word8 (UInt8 -> Builder) -> (UInt8 -> UInt8) -> UInt8 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt8 -> UInt8
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable UInt16 where serialize :: ProtocolRevision -> UInt16 -> Builder
serialize ProtocolRevision
_ = UInt16 -> Builder
word16LE (UInt16 -> Builder) -> (UInt16 -> UInt16) -> UInt16 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt16 -> UInt16
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable UInt32 where serialize :: ProtocolRevision -> UInt32 -> Builder
serialize ProtocolRevision
_ = UInt32 -> Builder
word32LE (UInt32 -> Builder) -> (UInt32 -> UInt32) -> UInt32 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt32 -> UInt32
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable UInt64 where serialize :: ProtocolRevision -> UInt64 -> Builder
serialize ProtocolRevision
_ = UInt64 -> Builder
word64LE (UInt64 -> Builder) -> (UInt64 -> UInt64) -> UInt64 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt64 -> UInt64
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable UInt128 where serialize :: ProtocolRevision -> UInt128 -> Builder
serialize ProtocolRevision
_ = (\(Word128 UInt64
hi UInt64
lo) -> UInt64 -> Builder
word64LE UInt64
lo Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> UInt64 -> Builder
word64LE UInt64
hi) (UInt128 -> Builder) -> (UInt128 -> UInt128) -> UInt128 -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UInt128 -> UInt128
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable (DateTime tz) where serialize :: ProtocolRevision -> DateTime tz -> Builder
serialize ProtocolRevision
_ = UInt32 -> Builder
word32LE (UInt32 -> Builder)
-> (DateTime tz -> UInt32) -> DateTime tz -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DateTime tz -> UInt32
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable (DateTime64 precision tz) where serialize :: ProtocolRevision -> DateTime64 precision tz -> Builder
serialize ProtocolRevision
_ = UInt64 -> Builder
word64LE (UInt64 -> Builder)
-> (DateTime64 precision tz -> UInt64)
-> DateTime64 precision tz
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DateTime64 precision tz -> UInt64
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
instance Serializable Date where serialize :: ProtocolRevision -> Date -> Builder
serialize ProtocolRevision
_ = UInt16 -> Builder
word16LE (UInt16 -> Builder) -> (Date -> UInt16) -> Date -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Date -> UInt16
forall chType outputType.
FromChType chType outputType =>
chType -> outputType
fromChType
class GSerial f where
gSerialize :: ProtocolRevision -> f p -> Builder
instance GSerial f => GSerial (D1 c (C1 c2 f)) where
gSerialize :: forall p. ProtocolRevision -> D1 c (C1 c2 f) p -> Builder
gSerialize ProtocolRevision
rev (M1 (M1 f p
re)) = ProtocolRevision -> f p -> Builder
forall p. ProtocolRevision -> f p -> Builder
forall (f :: * -> *) p.
GSerial f =>
ProtocolRevision -> f p -> Builder
gSerialize ProtocolRevision
rev f p
re
{-# INLINE gSerialize #-}
instance (GSerial left1, GSerial right) => GSerial (left1 :*: right) where
gSerialize :: forall p. ProtocolRevision -> (:*:) left1 right p -> Builder
gSerialize ProtocolRevision
rev (left1 p
l :*: right p
r) = ProtocolRevision -> left1 p -> Builder
forall p. ProtocolRevision -> left1 p -> Builder
forall (f :: * -> *) p.
GSerial f =>
ProtocolRevision -> f p -> Builder
gSerialize ProtocolRevision
rev left1 p
l Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> ProtocolRevision -> right p -> Builder
forall p. ProtocolRevision -> right p -> Builder
forall (f :: * -> *) p.
GSerial f =>
ProtocolRevision -> f p -> Builder
gSerialize ProtocolRevision
rev right p
r
{-# INLINE gSerialize #-}
instance Serializable chType => GSerial (S1 metaSel (Rec0 chType)) where
gSerialize :: forall p. ProtocolRevision -> S1 metaSel (Rec0 chType) p -> Builder
gSerialize ProtocolRevision
rev (M1 (K1 chType
re)) = ProtocolRevision -> chType -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev chType
re
{-# INLINE gSerialize #-}
class ToChType chType inputType where toChType :: inputType -> chType
instance {-# OVERLAPPABLE #-} (IsChType chType, chType ~ inputType) => ToChType chType inputType where toChType :: inputType -> chType
toChType = inputType -> chType
inputType -> inputType
forall a. a -> a
id
instance ToChType Int64 Int where toChType :: Int -> Int64
toChType = Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
instance ToChType UInt128 UInt64 where toChType :: UInt64 -> UInt128
toChType = UInt64 -> UInt128
forall a b. (Integral a, Num b) => a -> b
fromIntegral
instance ToChType ChString BS.ByteString where toChType :: ByteString -> ChString
toChType = ByteString -> ChString
MkChString
instance ToChType ChString Builder where toChType :: Builder -> ChString
toChType = ByteString -> ChString
MkChString (ByteString -> ChString)
-> (Builder -> ByteString) -> Builder -> ChString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
toStrict (ByteString -> ByteString)
-> (Builder -> ByteString) -> Builder -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
toLazyByteString
instance ToChType ChString String where toChType :: String -> ChString
toChType = ByteString -> ChString
MkChString (ByteString -> ChString)
-> (String -> ByteString) -> String -> ChString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack
instance ToChType ChString Text where toChType :: Text -> ChString
toChType = ByteString -> ChString
MkChString (ByteString -> ChString)
-> (Text -> ByteString) -> Text -> ChString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
Text.encodeUtf8
instance ToChType ChString Int where toChType :: Int -> ChString
toChType = ByteString -> ChString
MkChString (ByteString -> ChString) -> (Int -> ByteString) -> Int -> ChString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BS8.pack (String -> ByteString) -> (Int -> String) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show
instance
ToChType inputType chType
=>
ToChType (Nullable inputType) (Nullable chType)
where
toChType :: Nullable chType -> Nullable inputType
toChType = (chType -> inputType) -> Nullable chType -> Nullable inputType
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType @inputType @chType)
instance ToChType inputType chType => ToChType (LowCardinality inputType) chType where toChType :: chType -> LowCardinality inputType
toChType = inputType -> LowCardinality inputType
forall chType. chType -> LowCardinality chType
MkLowCardinality (inputType -> LowCardinality inputType)
-> (chType -> inputType) -> chType -> LowCardinality inputType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. chType -> inputType
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType
instance ToChType UUID Word64 where toChType :: UInt64 -> UUID
toChType = UInt128 -> UUID
MkChUUID (UInt128 -> UUID) -> (UInt64 -> UInt128) -> UInt64 -> UUID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UInt64 -> UInt64 -> UInt128) -> UInt64 -> UInt64 -> UInt128
forall a b c. (a -> b -> c) -> b -> a -> c
flip UInt64 -> UInt64 -> UInt128
Word128 UInt64
0
instance ToChType UUID (Word64, Word64) where toChType :: (UInt64, UInt64) -> UUID
toChType = UInt128 -> UUID
MkChUUID (UInt128 -> UUID)
-> ((UInt64, UInt64) -> UInt128) -> (UInt64, UInt64) -> UUID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UInt64 -> UInt64 -> UInt128) -> (UInt64, UInt64) -> UInt128
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((UInt64 -> UInt64 -> UInt128) -> UInt64 -> UInt64 -> UInt128
forall a b c. (a -> b -> c) -> b -> a -> c
flip UInt64 -> UInt64 -> UInt128
Word128)
instance ToChType (DateTime tz) Word32 where toChType :: UInt32 -> DateTime tz
toChType = UInt32 -> DateTime tz
forall (tz :: Symbol). UInt32 -> DateTime tz
MkDateTime
instance ToChType (DateTime tz) UTCTime where toChType :: UTCTime -> DateTime tz
toChType = UInt32 -> DateTime tz
forall (tz :: Symbol). UInt32 -> DateTime tz
MkDateTime (UInt32 -> DateTime tz)
-> (UTCTime -> UInt32) -> UTCTime -> DateTime tz
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UInt32
forall b. Integral b => POSIXTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (POSIXTime -> UInt32)
-> (UTCTime -> POSIXTime) -> UTCTime -> UInt32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds
instance ToChType (DateTime tz) ZonedTime where toChType :: ZonedTime -> DateTime tz
toChType = UInt32 -> DateTime tz
forall (tz :: Symbol). UInt32 -> DateTime tz
MkDateTime (UInt32 -> DateTime tz)
-> (ZonedTime -> UInt32) -> ZonedTime -> DateTime tz
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UInt32
forall b. Integral b => POSIXTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (POSIXTime -> UInt32)
-> (ZonedTime -> POSIXTime) -> ZonedTime -> UInt32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds (UTCTime -> POSIXTime)
-> (ZonedTime -> UTCTime) -> ZonedTime -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC
instance ToChType (DateTime64 precision tz) Word64 where toChType :: UInt64 -> DateTime64 precision tz
toChType = UInt64 -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
UInt64 -> DateTime64 precision tz
MkDateTime64
instance ToChType Date Word16 where toChType :: UInt16 -> Date
toChType = UInt16 -> Date
MkChDate
instance ToChType chType inputType => ToChType (Array chType) [inputType]
where
toChType :: [inputType] -> Array chType
toChType = [chType] -> Array chType
forall a. [a] -> Array a
MkChArray ([chType] -> Array chType)
-> ([inputType] -> [chType]) -> [inputType] -> Array chType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (inputType -> chType) -> [inputType] -> [chType]
forall a b. (a -> b) -> [a] -> [b]
map inputType -> chType
forall chType inputType.
ToChType chType inputType =>
inputType -> chType
toChType
class IsChType chType
where
chTypeName :: String
defaultValueOfTypeName :: chType
instance IsChType Int8 where; chTypeName :: String
chTypeName = String
"Int8"; defaultValueOfTypeName :: Int8
defaultValueOfTypeName = Int8
0
instance IsChType Int16 where; chTypeName :: String
chTypeName = String
"Int16"; defaultValueOfTypeName :: Int16
defaultValueOfTypeName = Int16
0
instance IsChType Int32 where; chTypeName :: String
chTypeName = String
"Int32"; defaultValueOfTypeName :: Int32
defaultValueOfTypeName = Int32
0
instance IsChType Int64 where; chTypeName :: String
chTypeName = String
"Int64"; defaultValueOfTypeName :: Int64
defaultValueOfTypeName = Int64
0
instance IsChType Int128 where; chTypeName :: String
chTypeName = String
"Int128"; defaultValueOfTypeName :: Int128
defaultValueOfTypeName = Int128
0
type UInt8 = Word8
instance IsChType UInt8 where; chTypeName :: String
chTypeName = String
"UInt8"; defaultValueOfTypeName :: UInt8
defaultValueOfTypeName = UInt8
0
type UInt16 = Word16
instance IsChType UInt16 where; chTypeName :: String
chTypeName = String
"UInt16"; defaultValueOfTypeName :: UInt16
defaultValueOfTypeName = UInt16
0
type UInt32 = Word32
instance IsChType UInt32 where; chTypeName :: String
chTypeName = String
"UInt32"; defaultValueOfTypeName :: UInt32
defaultValueOfTypeName = UInt32
0
type UInt64 = Word64
instance IsChType UInt64 where; chTypeName :: String
chTypeName = String
"UInt64"; defaultValueOfTypeName :: UInt64
defaultValueOfTypeName = UInt64
0
type UInt128 = Word128
instance IsChType UInt128 where; chTypeName :: String
chTypeName = String
"UInt128"; defaultValueOfTypeName :: UInt128
defaultValueOfTypeName = UInt128
0
newtype Date = MkChDate Word16
deriving newtype (Int -> Date -> String -> String
[Date] -> String -> String
Date -> String
(Int -> Date -> String -> String)
-> (Date -> String) -> ([Date] -> String -> String) -> Show Date
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> Date -> String -> String
showsPrec :: Int -> Date -> String -> String
$cshow :: Date -> String
show :: Date -> String
$cshowList :: [Date] -> String -> String
showList :: [Date] -> String -> String
Show, Date -> Date -> Bool
(Date -> Date -> Bool) -> (Date -> Date -> Bool) -> Eq Date
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Date -> Date -> Bool
== :: Date -> Date -> Bool
$c/= :: Date -> Date -> Bool
/= :: Date -> Date -> Bool
Eq, Eq Date
Date
Eq Date =>
(Date -> Date -> Date)
-> (Date -> Date -> Date)
-> (Date -> Date -> Date)
-> (Date -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> Date
-> (Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Bool)
-> (Date -> Maybe Int)
-> (Date -> Int)
-> (Date -> Bool)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int -> Date)
-> (Date -> Int)
-> Bits Date
Int -> Date
Date -> Bool
Date -> Int
Date -> Maybe Int
Date -> Date
Date -> Int -> Bool
Date -> Int -> Date
Date -> Date -> Date
forall a.
Eq a =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
$c.&. :: Date -> Date -> Date
.&. :: Date -> Date -> Date
$c.|. :: Date -> Date -> Date
.|. :: Date -> Date -> Date
$cxor :: Date -> Date -> Date
xor :: Date -> Date -> Date
$ccomplement :: Date -> Date
complement :: Date -> Date
$cshift :: Date -> Int -> Date
shift :: Date -> Int -> Date
$crotate :: Date -> Int -> Date
rotate :: Date -> Int -> Date
$czeroBits :: Date
zeroBits :: Date
$cbit :: Int -> Date
bit :: Int -> Date
$csetBit :: Date -> Int -> Date
setBit :: Date -> Int -> Date
$cclearBit :: Date -> Int -> Date
clearBit :: Date -> Int -> Date
$ccomplementBit :: Date -> Int -> Date
complementBit :: Date -> Int -> Date
$ctestBit :: Date -> Int -> Bool
testBit :: Date -> Int -> Bool
$cbitSizeMaybe :: Date -> Maybe Int
bitSizeMaybe :: Date -> Maybe Int
$cbitSize :: Date -> Int
bitSize :: Date -> Int
$cisSigned :: Date -> Bool
isSigned :: Date -> Bool
$cshiftL :: Date -> Int -> Date
shiftL :: Date -> Int -> Date
$cunsafeShiftL :: Date -> Int -> Date
unsafeShiftL :: Date -> Int -> Date
$cshiftR :: Date -> Int -> Date
shiftR :: Date -> Int -> Date
$cunsafeShiftR :: Date -> Int -> Date
unsafeShiftR :: Date -> Int -> Date
$crotateL :: Date -> Int -> Date
rotateL :: Date -> Int -> Date
$crotateR :: Date -> Int -> Date
rotateR :: Date -> Int -> Date
$cpopCount :: Date -> Int
popCount :: Date -> Int
Bits, Date
Date -> Date -> Bounded Date
forall a. a -> a -> Bounded a
$cminBound :: Date
minBound :: Date
$cmaxBound :: Date
maxBound :: Date
Bounded, Int -> Date
Date -> Int
Date -> [Date]
Date -> Date
Date -> Date -> [Date]
Date -> Date -> Date -> [Date]
(Date -> Date)
-> (Date -> Date)
-> (Int -> Date)
-> (Date -> Int)
-> (Date -> [Date])
-> (Date -> Date -> [Date])
-> (Date -> Date -> [Date])
-> (Date -> Date -> Date -> [Date])
-> Enum Date
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Date -> Date
succ :: Date -> Date
$cpred :: Date -> Date
pred :: Date -> Date
$ctoEnum :: Int -> Date
toEnum :: Int -> Date
$cfromEnum :: Date -> Int
fromEnum :: Date -> Int
$cenumFrom :: Date -> [Date]
enumFrom :: Date -> [Date]
$cenumFromThen :: Date -> Date -> [Date]
enumFromThen :: Date -> Date -> [Date]
$cenumFromTo :: Date -> Date -> [Date]
enumFromTo :: Date -> Date -> [Date]
$cenumFromThenTo :: Date -> Date -> Date -> [Date]
enumFromThenTo :: Date -> Date -> Date -> [Date]
Enum, Date -> ()
(Date -> ()) -> NFData Date
forall a. (a -> ()) -> NFData a
$crnf :: Date -> ()
rnf :: Date -> ()
NFData, Integer -> Date
Date -> Date
Date -> Date -> Date
(Date -> Date -> Date)
-> (Date -> Date -> Date)
-> (Date -> Date -> Date)
-> (Date -> Date)
-> (Date -> Date)
-> (Date -> Date)
-> (Integer -> Date)
-> Num Date
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: Date -> Date -> Date
+ :: Date -> Date -> Date
$c- :: Date -> Date -> Date
- :: Date -> Date -> Date
$c* :: Date -> Date -> Date
* :: Date -> Date -> Date
$cnegate :: Date -> Date
negate :: Date -> Date
$cabs :: Date -> Date
abs :: Date -> Date
$csignum :: Date -> Date
signum :: Date -> Date
$cfromInteger :: Integer -> Date
fromInteger :: Integer -> Date
Num)
instance IsChType Date where; chTypeName :: String
chTypeName = String
"Date"; defaultValueOfTypeName :: Date
defaultValueOfTypeName = Date
0
newtype ChString = MkChString BS.ByteString
deriving newtype (Int -> ChString -> String -> String
[ChString] -> String -> String
ChString -> String
(Int -> ChString -> String -> String)
-> (ChString -> String)
-> ([ChString] -> String -> String)
-> Show ChString
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> ChString -> String -> String
showsPrec :: Int -> ChString -> String -> String
$cshow :: ChString -> String
show :: ChString -> String
$cshowList :: [ChString] -> String -> String
showList :: [ChString] -> String -> String
Show, ChString -> ChString -> Bool
(ChString -> ChString -> Bool)
-> (ChString -> ChString -> Bool) -> Eq ChString
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChString -> ChString -> Bool
== :: ChString -> ChString -> Bool
$c/= :: ChString -> ChString -> Bool
/= :: ChString -> ChString -> Bool
Eq, String -> ChString
(String -> ChString) -> IsString ChString
forall a. (String -> a) -> IsString a
$cfromString :: String -> ChString
fromString :: String -> ChString
IsString, ChString -> ()
(ChString -> ()) -> NFData ChString
forall a. (a -> ()) -> NFData a
$crnf :: ChString -> ()
rnf :: ChString -> ()
NFData)
instance IsChType ChString where; chTypeName :: String
chTypeName = String
"String"; defaultValueOfTypeName :: ChString
defaultValueOfTypeName = ChString
""
newtype UUID = MkChUUID Word128
deriving newtype ((forall x. UUID -> Rep UUID x)
-> (forall x. Rep UUID x -> UUID) -> Generic UUID
forall x. Rep UUID x -> UUID
forall x. UUID -> Rep UUID x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. UUID -> Rep UUID x
from :: forall x. UUID -> Rep UUID x
$cto :: forall x. Rep UUID x -> UUID
to :: forall x. Rep UUID x -> UUID
Generic, Int -> UUID -> String -> String
[UUID] -> String -> String
UUID -> String
(Int -> UUID -> String -> String)
-> (UUID -> String) -> ([UUID] -> String -> String) -> Show UUID
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> UUID -> String -> String
showsPrec :: Int -> UUID -> String -> String
$cshow :: UUID -> String
show :: UUID -> String
$cshowList :: [UUID] -> String -> String
showList :: [UUID] -> String -> String
Show, UUID -> UUID -> Bool
(UUID -> UUID -> Bool) -> (UUID -> UUID -> Bool) -> Eq UUID
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UUID -> UUID -> Bool
== :: UUID -> UUID -> Bool
$c/= :: UUID -> UUID -> Bool
/= :: UUID -> UUID -> Bool
Eq, UUID -> ()
(UUID -> ()) -> NFData UUID
forall a. (a -> ()) -> NFData a
$crnf :: UUID -> ()
rnf :: UUID -> ()
NFData, UUID
UUID -> UUID -> Bounded UUID
forall a. a -> a -> Bounded a
$cminBound :: UUID
minBound :: UUID
$cmaxBound :: UUID
maxBound :: UUID
Bounded, Int -> UUID
UUID -> Int
UUID -> [UUID]
UUID -> UUID
UUID -> UUID -> [UUID]
UUID -> UUID -> UUID -> [UUID]
(UUID -> UUID)
-> (UUID -> UUID)
-> (Int -> UUID)
-> (UUID -> Int)
-> (UUID -> [UUID])
-> (UUID -> UUID -> [UUID])
-> (UUID -> UUID -> [UUID])
-> (UUID -> UUID -> UUID -> [UUID])
-> Enum UUID
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: UUID -> UUID
succ :: UUID -> UUID
$cpred :: UUID -> UUID
pred :: UUID -> UUID
$ctoEnum :: Int -> UUID
toEnum :: Int -> UUID
$cfromEnum :: UUID -> Int
fromEnum :: UUID -> Int
$cenumFrom :: UUID -> [UUID]
enumFrom :: UUID -> [UUID]
$cenumFromThen :: UUID -> UUID -> [UUID]
enumFromThen :: UUID -> UUID -> [UUID]
$cenumFromTo :: UUID -> UUID -> [UUID]
enumFromTo :: UUID -> UUID -> [UUID]
$cenumFromThenTo :: UUID -> UUID -> UUID -> [UUID]
enumFromThenTo :: UUID -> UUID -> UUID -> [UUID]
Enum, Integer -> UUID
UUID -> UUID
UUID -> UUID -> UUID
(UUID -> UUID -> UUID)
-> (UUID -> UUID -> UUID)
-> (UUID -> UUID -> UUID)
-> (UUID -> UUID)
-> (UUID -> UUID)
-> (UUID -> UUID)
-> (Integer -> UUID)
-> Num UUID
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: UUID -> UUID -> UUID
+ :: UUID -> UUID -> UUID
$c- :: UUID -> UUID -> UUID
- :: UUID -> UUID -> UUID
$c* :: UUID -> UUID -> UUID
* :: UUID -> UUID -> UUID
$cnegate :: UUID -> UUID
negate :: UUID -> UUID
$cabs :: UUID -> UUID
abs :: UUID -> UUID
$csignum :: UUID -> UUID
signum :: UUID -> UUID
$cfromInteger :: Integer -> UUID
fromInteger :: Integer -> UUID
Num)
instance IsChType UUID where; chTypeName :: String
chTypeName = String
"UUID"; defaultValueOfTypeName :: UUID
defaultValueOfTypeName = UUID
0
type Nullable = Maybe
instance IsChType chType => IsChType (Nullable chType)
where
chTypeName :: String
chTypeName = String
"Nullable(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> forall chType. IsChType chType => String
chTypeName @chType String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
defaultValueOfTypeName :: Nullable chType
defaultValueOfTypeName = Nullable chType
forall a. Maybe a
Nothing
newtype DateTime (tz :: Symbol) = MkDateTime Word32
deriving newtype (Int -> DateTime tz -> String -> String
[DateTime tz] -> String -> String
DateTime tz -> String
(Int -> DateTime tz -> String -> String)
-> (DateTime tz -> String)
-> ([DateTime tz] -> String -> String)
-> Show (DateTime tz)
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
forall (tz :: Symbol). Int -> DateTime tz -> String -> String
forall (tz :: Symbol). [DateTime tz] -> String -> String
forall (tz :: Symbol). DateTime tz -> String
$cshowsPrec :: forall (tz :: Symbol). Int -> DateTime tz -> String -> String
showsPrec :: Int -> DateTime tz -> String -> String
$cshow :: forall (tz :: Symbol). DateTime tz -> String
show :: DateTime tz -> String
$cshowList :: forall (tz :: Symbol). [DateTime tz] -> String -> String
showList :: [DateTime tz] -> String -> String
Show, DateTime tz -> DateTime tz -> Bool
(DateTime tz -> DateTime tz -> Bool)
-> (DateTime tz -> DateTime tz -> Bool) -> Eq (DateTime tz)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
$c== :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
== :: DateTime tz -> DateTime tz -> Bool
$c/= :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
/= :: DateTime tz -> DateTime tz -> Bool
Eq, Integer -> DateTime tz
DateTime tz -> DateTime tz
DateTime tz -> DateTime tz -> DateTime tz
(DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz)
-> (Integer -> DateTime tz)
-> Num (DateTime tz)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
forall (tz :: Symbol). Integer -> DateTime tz
forall (tz :: Symbol). DateTime tz -> DateTime tz
forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
$c+ :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
+ :: DateTime tz -> DateTime tz -> DateTime tz
$c- :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
- :: DateTime tz -> DateTime tz -> DateTime tz
$c* :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
* :: DateTime tz -> DateTime tz -> DateTime tz
$cnegate :: forall (tz :: Symbol). DateTime tz -> DateTime tz
negate :: DateTime tz -> DateTime tz
$cabs :: forall (tz :: Symbol). DateTime tz -> DateTime tz
abs :: DateTime tz -> DateTime tz
$csignum :: forall (tz :: Symbol). DateTime tz -> DateTime tz
signum :: DateTime tz -> DateTime tz
$cfromInteger :: forall (tz :: Symbol). Integer -> DateTime tz
fromInteger :: Integer -> DateTime tz
Num, Eq (DateTime tz)
DateTime tz
Eq (DateTime tz) =>
(DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> DateTime tz
-> (Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> Bool)
-> (DateTime tz -> Maybe Int)
-> (DateTime tz -> Int)
-> (DateTime tz -> Bool)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int -> DateTime tz)
-> (DateTime tz -> Int)
-> Bits (DateTime tz)
Int -> DateTime tz
DateTime tz -> Bool
DateTime tz -> Int
DateTime tz -> Maybe Int
DateTime tz -> DateTime tz
DateTime tz -> Int -> Bool
DateTime tz -> Int -> DateTime tz
DateTime tz -> DateTime tz -> DateTime tz
forall a.
Eq a =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall (tz :: Symbol). Eq (DateTime tz)
forall (tz :: Symbol). DateTime tz
forall (tz :: Symbol). Int -> DateTime tz
forall (tz :: Symbol). DateTime tz -> Bool
forall (tz :: Symbol). DateTime tz -> Int
forall (tz :: Symbol). DateTime tz -> Maybe Int
forall (tz :: Symbol). DateTime tz -> DateTime tz
forall (tz :: Symbol). DateTime tz -> Int -> Bool
forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
$c.&. :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
.&. :: DateTime tz -> DateTime tz -> DateTime tz
$c.|. :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
.|. :: DateTime tz -> DateTime tz -> DateTime tz
$cxor :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
xor :: DateTime tz -> DateTime tz -> DateTime tz
$ccomplement :: forall (tz :: Symbol). DateTime tz -> DateTime tz
complement :: DateTime tz -> DateTime tz
$cshift :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
shift :: DateTime tz -> Int -> DateTime tz
$crotate :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
rotate :: DateTime tz -> Int -> DateTime tz
$czeroBits :: forall (tz :: Symbol). DateTime tz
zeroBits :: DateTime tz
$cbit :: forall (tz :: Symbol). Int -> DateTime tz
bit :: Int -> DateTime tz
$csetBit :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
setBit :: DateTime tz -> Int -> DateTime tz
$cclearBit :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
clearBit :: DateTime tz -> Int -> DateTime tz
$ccomplementBit :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
complementBit :: DateTime tz -> Int -> DateTime tz
$ctestBit :: forall (tz :: Symbol). DateTime tz -> Int -> Bool
testBit :: DateTime tz -> Int -> Bool
$cbitSizeMaybe :: forall (tz :: Symbol). DateTime tz -> Maybe Int
bitSizeMaybe :: DateTime tz -> Maybe Int
$cbitSize :: forall (tz :: Symbol). DateTime tz -> Int
bitSize :: DateTime tz -> Int
$cisSigned :: forall (tz :: Symbol). DateTime tz -> Bool
isSigned :: DateTime tz -> Bool
$cshiftL :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
shiftL :: DateTime tz -> Int -> DateTime tz
$cunsafeShiftL :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
unsafeShiftL :: DateTime tz -> Int -> DateTime tz
$cshiftR :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
shiftR :: DateTime tz -> Int -> DateTime tz
$cunsafeShiftR :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
unsafeShiftR :: DateTime tz -> Int -> DateTime tz
$crotateL :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
rotateL :: DateTime tz -> Int -> DateTime tz
$crotateR :: forall (tz :: Symbol). DateTime tz -> Int -> DateTime tz
rotateR :: DateTime tz -> Int -> DateTime tz
$cpopCount :: forall (tz :: Symbol). DateTime tz -> Int
popCount :: DateTime tz -> Int
Bits, Int -> DateTime tz
DateTime tz -> Int
DateTime tz -> [DateTime tz]
DateTime tz -> DateTime tz
DateTime tz -> DateTime tz -> [DateTime tz]
DateTime tz -> DateTime tz -> DateTime tz -> [DateTime tz]
(DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz)
-> (Int -> DateTime tz)
-> (DateTime tz -> Int)
-> (DateTime tz -> [DateTime tz])
-> (DateTime tz -> DateTime tz -> [DateTime tz])
-> (DateTime tz -> DateTime tz -> [DateTime tz])
-> (DateTime tz -> DateTime tz -> DateTime tz -> [DateTime tz])
-> Enum (DateTime tz)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
forall (tz :: Symbol). Int -> DateTime tz
forall (tz :: Symbol). DateTime tz -> Int
forall (tz :: Symbol). DateTime tz -> [DateTime tz]
forall (tz :: Symbol). DateTime tz -> DateTime tz
forall (tz :: Symbol). DateTime tz -> DateTime tz -> [DateTime tz]
forall (tz :: Symbol).
DateTime tz -> DateTime tz -> DateTime tz -> [DateTime tz]
$csucc :: forall (tz :: Symbol). DateTime tz -> DateTime tz
succ :: DateTime tz -> DateTime tz
$cpred :: forall (tz :: Symbol). DateTime tz -> DateTime tz
pred :: DateTime tz -> DateTime tz
$ctoEnum :: forall (tz :: Symbol). Int -> DateTime tz
toEnum :: Int -> DateTime tz
$cfromEnum :: forall (tz :: Symbol). DateTime tz -> Int
fromEnum :: DateTime tz -> Int
$cenumFrom :: forall (tz :: Symbol). DateTime tz -> [DateTime tz]
enumFrom :: DateTime tz -> [DateTime tz]
$cenumFromThen :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> [DateTime tz]
enumFromThen :: DateTime tz -> DateTime tz -> [DateTime tz]
$cenumFromTo :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> [DateTime tz]
enumFromTo :: DateTime tz -> DateTime tz -> [DateTime tz]
$cenumFromThenTo :: forall (tz :: Symbol).
DateTime tz -> DateTime tz -> DateTime tz -> [DateTime tz]
enumFromThenTo :: DateTime tz -> DateTime tz -> DateTime tz -> [DateTime tz]
Enum, Eq (DateTime tz)
Eq (DateTime tz) =>
(DateTime tz -> DateTime tz -> Ordering)
-> (DateTime tz -> DateTime tz -> Bool)
-> (DateTime tz -> DateTime tz -> Bool)
-> (DateTime tz -> DateTime tz -> Bool)
-> (DateTime tz -> DateTime tz -> Bool)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> Ord (DateTime tz)
DateTime tz -> DateTime tz -> Bool
DateTime tz -> DateTime tz -> Ordering
DateTime tz -> DateTime tz -> DateTime tz
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall (tz :: Symbol). Eq (DateTime tz)
forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
forall (tz :: Symbol). DateTime tz -> DateTime tz -> Ordering
forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
$ccompare :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Ordering
compare :: DateTime tz -> DateTime tz -> Ordering
$c< :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
< :: DateTime tz -> DateTime tz -> Bool
$c<= :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
<= :: DateTime tz -> DateTime tz -> Bool
$c> :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
> :: DateTime tz -> DateTime tz -> Bool
$c>= :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> Bool
>= :: DateTime tz -> DateTime tz -> Bool
$cmax :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
max :: DateTime tz -> DateTime tz -> DateTime tz
$cmin :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
min :: DateTime tz -> DateTime tz -> DateTime tz
Ord, Num (DateTime tz)
Ord (DateTime tz)
(Num (DateTime tz), Ord (DateTime tz)) =>
(DateTime tz -> Rational) -> Real (DateTime tz)
DateTime tz -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
forall (tz :: Symbol). Num (DateTime tz)
forall (tz :: Symbol). Ord (DateTime tz)
forall (tz :: Symbol). DateTime tz -> Rational
$ctoRational :: forall (tz :: Symbol). DateTime tz -> Rational
toRational :: DateTime tz -> Rational
Real, Enum (DateTime tz)
Real (DateTime tz)
(Real (DateTime tz), Enum (DateTime tz)) =>
(DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> DateTime tz)
-> (DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz))
-> (DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz))
-> (DateTime tz -> Integer)
-> Integral (DateTime tz)
DateTime tz -> Integer
DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz)
DateTime tz -> DateTime tz -> DateTime tz
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
forall (tz :: Symbol). Enum (DateTime tz)
forall (tz :: Symbol). Real (DateTime tz)
forall (tz :: Symbol). DateTime tz -> Integer
forall (tz :: Symbol).
DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz)
forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
$cquot :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
quot :: DateTime tz -> DateTime tz -> DateTime tz
$crem :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
rem :: DateTime tz -> DateTime tz -> DateTime tz
$cdiv :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
div :: DateTime tz -> DateTime tz -> DateTime tz
$cmod :: forall (tz :: Symbol). DateTime tz -> DateTime tz -> DateTime tz
mod :: DateTime tz -> DateTime tz -> DateTime tz
$cquotRem :: forall (tz :: Symbol).
DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz)
quotRem :: DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz)
$cdivMod :: forall (tz :: Symbol).
DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz)
divMod :: DateTime tz -> DateTime tz -> (DateTime tz, DateTime tz)
$ctoInteger :: forall (tz :: Symbol). DateTime tz -> Integer
toInteger :: DateTime tz -> Integer
Integral, DateTime tz
DateTime tz -> DateTime tz -> Bounded (DateTime tz)
forall a. a -> a -> Bounded a
forall (tz :: Symbol). DateTime tz
$cminBound :: forall (tz :: Symbol). DateTime tz
minBound :: DateTime tz
$cmaxBound :: forall (tz :: Symbol). DateTime tz
maxBound :: DateTime tz
Bounded, DateTime tz -> ()
(DateTime tz -> ()) -> NFData (DateTime tz)
forall a. (a -> ()) -> NFData a
forall (tz :: Symbol). DateTime tz -> ()
$crnf :: forall (tz :: Symbol). DateTime tz -> ()
rnf :: DateTime tz -> ()
NFData)
type DateTimeTypeName tz = If (tz == "") ("DateTime") ("DateTime('" `AppendSymbol` tz `AppendSymbol` "')")
instance KnownSymbol (DateTimeTypeName tz) => IsChType (DateTime tz)
where
chTypeName :: String
chTypeName = forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(DateTimeTypeName tz) (Proxy (DateTimeTypeName tz) -> String)
-> Proxy (DateTimeTypeName tz) -> String
forall a b. (a -> b) -> a -> b
$ Proxy (DateTimeTypeName tz)
forall {k} (t :: k). Proxy t
Proxy
defaultValueOfTypeName :: DateTime tz
defaultValueOfTypeName = UInt32 -> DateTime tz
forall (tz :: Symbol). UInt32 -> DateTime tz
MkDateTime UInt32
0
newtype DateTime64 (precision :: Nat) (tz :: Symbol) = MkDateTime64 Word64
deriving newtype (Int -> DateTime64 precision tz -> String -> String
[DateTime64 precision tz] -> String -> String
DateTime64 precision tz -> String
(Int -> DateTime64 precision tz -> String -> String)
-> (DateTime64 precision tz -> String)
-> ([DateTime64 precision tz] -> String -> String)
-> Show (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
Int -> DateTime64 precision tz -> String -> String
forall (precision :: Nat) (tz :: Symbol).
[DateTime64 precision tz] -> String -> String
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: forall (precision :: Nat) (tz :: Symbol).
Int -> DateTime64 precision tz -> String -> String
showsPrec :: Int -> DateTime64 precision tz -> String -> String
$cshow :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> String
show :: DateTime64 precision tz -> String
$cshowList :: forall (precision :: Nat) (tz :: Symbol).
[DateTime64 precision tz] -> String -> String
showList :: [DateTime64 precision tz] -> String -> String
Show, DateTime64 precision tz -> DateTime64 precision tz -> Bool
(DateTime64 precision tz -> DateTime64 precision tz -> Bool)
-> (DateTime64 precision tz -> DateTime64 precision tz -> Bool)
-> Eq (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
== :: DateTime64 precision tz -> DateTime64 precision tz -> Bool
$c/= :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
/= :: DateTime64 precision tz -> DateTime64 precision tz -> Bool
Eq, Integer -> DateTime64 precision tz
DateTime64 precision tz -> DateTime64 precision tz
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
(DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz -> DateTime64 precision tz)
-> (Integer -> DateTime64 precision tz)
-> Num (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
Integer -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
+ :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$c- :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
- :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$c* :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
* :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$cnegate :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
negate :: DateTime64 precision tz -> DateTime64 precision tz
$cabs :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
abs :: DateTime64 precision tz -> DateTime64 precision tz
$csignum :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
signum :: DateTime64 precision tz -> DateTime64 precision tz
$cfromInteger :: forall (precision :: Nat) (tz :: Symbol).
Integer -> DateTime64 precision tz
fromInteger :: Integer -> DateTime64 precision tz
Num, Eq (DateTime64 precision tz)
DateTime64 precision tz
Eq (DateTime64 precision tz) =>
(DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> DateTime64 precision tz
-> (Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> Bool)
-> (DateTime64 precision tz -> Maybe Int)
-> (DateTime64 precision tz -> Int)
-> (DateTime64 precision tz -> Bool)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int)
-> Bits (DateTime64 precision tz)
Int -> DateTime64 precision tz
DateTime64 precision tz -> Bool
DateTime64 precision tz -> Int
DateTime64 precision tz -> Maybe Int
DateTime64 precision tz -> DateTime64 precision tz
DateTime64 precision tz -> Int -> Bool
DateTime64 precision tz -> Int -> DateTime64 precision tz
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
Eq (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol). DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
Int -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Bool
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Maybe Int
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> Bool
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall a.
Eq a =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
$c.&. :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
.&. :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$c.|. :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
.|. :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$cxor :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
xor :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$ccomplement :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
complement :: DateTime64 precision tz -> DateTime64 precision tz
$cshift :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
shift :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$crotate :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
rotate :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$czeroBits :: forall (precision :: Nat) (tz :: Symbol). DateTime64 precision tz
zeroBits :: DateTime64 precision tz
$cbit :: forall (precision :: Nat) (tz :: Symbol).
Int -> DateTime64 precision tz
bit :: Int -> DateTime64 precision tz
$csetBit :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
setBit :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$cclearBit :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
clearBit :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$ccomplementBit :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
complementBit :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$ctestBit :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> Bool
testBit :: DateTime64 precision tz -> Int -> Bool
$cbitSizeMaybe :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Maybe Int
bitSizeMaybe :: DateTime64 precision tz -> Maybe Int
$cbitSize :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int
bitSize :: DateTime64 precision tz -> Int
$cisSigned :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Bool
isSigned :: DateTime64 precision tz -> Bool
$cshiftL :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
shiftL :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$cunsafeShiftL :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
unsafeShiftL :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$cshiftR :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
shiftR :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$cunsafeShiftR :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
unsafeShiftR :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$crotateL :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
rotateL :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$crotateR :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int -> DateTime64 precision tz
rotateR :: DateTime64 precision tz -> Int -> DateTime64 precision tz
$cpopCount :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int
popCount :: DateTime64 precision tz -> Int
Bits, Int -> DateTime64 precision tz
DateTime64 precision tz -> Int
DateTime64 precision tz -> [DateTime64 precision tz]
DateTime64 precision tz -> DateTime64 precision tz
DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz]
DateTime64 precision tz
-> DateTime64 precision tz
-> DateTime64 precision tz
-> [DateTime64 precision tz]
(DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz -> DateTime64 precision tz)
-> (Int -> DateTime64 precision tz)
-> (DateTime64 precision tz -> Int)
-> (DateTime64 precision tz -> [DateTime64 precision tz])
-> (DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz])
-> (DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz])
-> (DateTime64 precision tz
-> DateTime64 precision tz
-> DateTime64 precision tz
-> [DateTime64 precision tz])
-> Enum (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
Int -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> [DateTime64 precision tz]
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz]
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz
-> DateTime64 precision tz
-> [DateTime64 precision tz]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
succ :: DateTime64 precision tz -> DateTime64 precision tz
$cpred :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz
pred :: DateTime64 precision tz -> DateTime64 precision tz
$ctoEnum :: forall (precision :: Nat) (tz :: Symbol).
Int -> DateTime64 precision tz
toEnum :: Int -> DateTime64 precision tz
$cfromEnum :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Int
fromEnum :: DateTime64 precision tz -> Int
$cenumFrom :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> [DateTime64 precision tz]
enumFrom :: DateTime64 precision tz -> [DateTime64 precision tz]
$cenumFromThen :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz]
enumFromThen :: DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz]
$cenumFromTo :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz]
enumFromTo :: DateTime64 precision tz
-> DateTime64 precision tz -> [DateTime64 precision tz]
$cenumFromThenTo :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz
-> DateTime64 precision tz
-> [DateTime64 precision tz]
enumFromThenTo :: DateTime64 precision tz
-> DateTime64 precision tz
-> DateTime64 precision tz
-> [DateTime64 precision tz]
Enum, Eq (DateTime64 precision tz)
Eq (DateTime64 precision tz) =>
(DateTime64 precision tz -> DateTime64 precision tz -> Ordering)
-> (DateTime64 precision tz -> DateTime64 precision tz -> Bool)
-> (DateTime64 precision tz -> DateTime64 precision tz -> Bool)
-> (DateTime64 precision tz -> DateTime64 precision tz -> Bool)
-> (DateTime64 precision tz -> DateTime64 precision tz -> Bool)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> Ord (DateTime64 precision tz)
DateTime64 precision tz -> DateTime64 precision tz -> Bool
DateTime64 precision tz -> DateTime64 precision tz -> Ordering
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
Eq (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Ordering
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Ordering
compare :: DateTime64 precision tz -> DateTime64 precision tz -> Ordering
$c< :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
< :: DateTime64 precision tz -> DateTime64 precision tz -> Bool
$c<= :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
<= :: DateTime64 precision tz -> DateTime64 precision tz -> Bool
$c> :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
> :: DateTime64 precision tz -> DateTime64 precision tz -> Bool
$c>= :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> DateTime64 precision tz -> Bool
>= :: DateTime64 precision tz -> DateTime64 precision tz -> Bool
$cmax :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
max :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$cmin :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
min :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
Ord, Num (DateTime64 precision tz)
Ord (DateTime64 precision tz)
(Num (DateTime64 precision tz), Ord (DateTime64 precision tz)) =>
(DateTime64 precision tz -> Rational)
-> Real (DateTime64 precision tz)
DateTime64 precision tz -> Rational
forall (precision :: Nat) (tz :: Symbol).
Num (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
Ord (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Rational
toRational :: DateTime64 precision tz -> Rational
Real, Enum (DateTime64 precision tz)
Real (DateTime64 precision tz)
(Real (DateTime64 precision tz), Enum (DateTime64 precision tz)) =>
(DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz)
-> (DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz))
-> (DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz))
-> (DateTime64 precision tz -> Integer)
-> Integral (DateTime64 precision tz)
DateTime64 precision tz -> Integer
DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz)
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
Enum (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
Real (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Integer
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
quot :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$crem :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
rem :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$cdiv :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
div :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$cmod :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
mod :: DateTime64 precision tz
-> DateTime64 precision tz -> DateTime64 precision tz
$cquotRem :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz)
quotRem :: DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz)
$cdivMod :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz)
divMod :: DateTime64 precision tz
-> DateTime64 precision tz
-> (DateTime64 precision tz, DateTime64 precision tz)
$ctoInteger :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> Integer
toInteger :: DateTime64 precision tz -> Integer
Integral, DateTime64 precision tz
DateTime64 precision tz
-> DateTime64 precision tz -> Bounded (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol). DateTime64 precision tz
forall a. a -> a -> Bounded a
$cminBound :: forall (precision :: Nat) (tz :: Symbol). DateTime64 precision tz
minBound :: DateTime64 precision tz
$cmaxBound :: forall (precision :: Nat) (tz :: Symbol). DateTime64 precision tz
maxBound :: DateTime64 precision tz
Bounded, DateTime64 precision tz -> ()
(DateTime64 precision tz -> ()) -> NFData (DateTime64 precision tz)
forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> ()
forall a. (a -> ()) -> NFData a
$crnf :: forall (precision :: Nat) (tz :: Symbol).
DateTime64 precision tz -> ()
rnf :: DateTime64 precision tz -> ()
NFData)
instance
(KnownSymbol tz, KnownNat precision)
=>
IsChType (DateTime64 precision tz)
where
chTypeName :: String
chTypeName =
let
prec :: String
prec = Integer -> String
forall a. Show a => a -> String
show (forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal @precision Proxy precision
forall {k} (t :: k). Proxy t
Proxy)
tz :: String
tz = forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @tz Proxy tz
forall {k} (t :: k). Proxy t
Proxy
in
case String
tz of
String
"" -> String
"DateTime64(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
prec String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
String
_ -> String
"DateTime64(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
prec String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
", '" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
tz String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"')"
defaultValueOfTypeName :: DateTime64 precision tz
defaultValueOfTypeName = UInt64 -> DateTime64 precision tz
forall (precision :: Nat) (tz :: Symbol).
UInt64 -> DateTime64 precision tz
MkDateTime64 UInt64
0
newtype Array a = MkChArray [a]
deriving newtype (Int -> Array a -> String -> String
[Array a] -> String -> String
Array a -> String
(Int -> Array a -> String -> String)
-> (Array a -> String)
-> ([Array a] -> String -> String)
-> Show (Array a)
forall a. Show a => Int -> Array a -> String -> String
forall a. Show a => [Array a] -> String -> String
forall a. Show a => Array a -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Array a -> String -> String
showsPrec :: Int -> Array a -> String -> String
$cshow :: forall a. Show a => Array a -> String
show :: Array a -> String
$cshowList :: forall a. Show a => [Array a] -> String -> String
showList :: [Array a] -> String -> String
Show, Array a -> Array a -> Bool
(Array a -> Array a -> Bool)
-> (Array a -> Array a -> Bool) -> Eq (Array a)
forall a. Eq a => Array a -> Array a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Array a -> Array a -> Bool
== :: Array a -> Array a -> Bool
$c/= :: forall a. Eq a => Array a -> Array a -> Bool
/= :: Array a -> Array a -> Bool
Eq, Array a -> ()
(Array a -> ()) -> NFData (Array a)
forall a. NFData a => Array a -> ()
forall a. (a -> ()) -> NFData a
$crnf :: forall a. NFData a => Array a -> ()
rnf :: Array a -> ()
NFData)
instance IsChType chType => IsChType (Array chType)
where
chTypeName :: String
chTypeName = String
"Array(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> forall chType. IsChType chType => String
chTypeName @chType String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
defaultValueOfTypeName :: Array chType
defaultValueOfTypeName = [chType] -> Array chType
forall a. [a] -> Array a
MkChArray []
newtype LowCardinality chType = MkLowCardinality chType
instance IsLowCardinalitySupported chType => IsChType (LowCardinality chType)
where
chTypeName :: String
chTypeName = String
"LowCardinality(" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> forall chType. IsChType chType => String
chTypeName @chType String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
")"
defaultValueOfTypeName :: LowCardinality chType
defaultValueOfTypeName = chType -> LowCardinality chType
forall chType. chType -> LowCardinality chType
MkLowCardinality (chType -> LowCardinality chType)
-> chType -> LowCardinality chType
forall a b. (a -> b) -> a -> b
$ forall chType. IsChType chType => chType
defaultValueOfTypeName @chType
deriving newtype instance (Eq chType, IsLowCardinalitySupported chType) => Eq (LowCardinality chType)
deriving newtype instance (NFData chType, IsLowCardinalitySupported chType) => NFData (LowCardinality chType)
deriving newtype instance IsString (LowCardinality ChString)
class IsChType chType => IsLowCardinalitySupported chType
instance IsLowCardinalitySupported ChString
instance
( IsLowCardinalitySupported chType
, IsChType (Nullable chType)
) =>
IsLowCardinalitySupported (Nullable chType)
instance {-# OVERLAPPABLE #-}
( IsChType chType
, TypeError
( 'Text "LowCardinality(" ':<>: 'ShowType chType ':<>: 'Text ") is unsupported"
':$$: 'Text "Use one of these types:"
':$$: 'Text " ChString"
':$$: 'Text " DateTime"
':$$: 'Text " Nullable(T)"
)
) => IsLowCardinalitySupported chType
newtype UVarInt = MkUVarInt Word64
deriving newtype (Int -> UVarInt -> String -> String
[UVarInt] -> String -> String
UVarInt -> String
(Int -> UVarInt -> String -> String)
-> (UVarInt -> String)
-> ([UVarInt] -> String -> String)
-> Show UVarInt
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> UVarInt -> String -> String
showsPrec :: Int -> UVarInt -> String -> String
$cshow :: UVarInt -> String
show :: UVarInt -> String
$cshowList :: [UVarInt] -> String -> String
showList :: [UVarInt] -> String -> String
Show, UVarInt -> UVarInt -> Bool
(UVarInt -> UVarInt -> Bool)
-> (UVarInt -> UVarInt -> Bool) -> Eq UVarInt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UVarInt -> UVarInt -> Bool
== :: UVarInt -> UVarInt -> Bool
$c/= :: UVarInt -> UVarInt -> Bool
/= :: UVarInt -> UVarInt -> Bool
Eq, Integer -> UVarInt
UVarInt -> UVarInt
UVarInt -> UVarInt -> UVarInt
(UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt)
-> (UVarInt -> UVarInt)
-> (UVarInt -> UVarInt)
-> (Integer -> UVarInt)
-> Num UVarInt
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: UVarInt -> UVarInt -> UVarInt
+ :: UVarInt -> UVarInt -> UVarInt
$c- :: UVarInt -> UVarInt -> UVarInt
- :: UVarInt -> UVarInt -> UVarInt
$c* :: UVarInt -> UVarInt -> UVarInt
* :: UVarInt -> UVarInt -> UVarInt
$cnegate :: UVarInt -> UVarInt
negate :: UVarInt -> UVarInt
$cabs :: UVarInt -> UVarInt
abs :: UVarInt -> UVarInt
$csignum :: UVarInt -> UVarInt
signum :: UVarInt -> UVarInt
$cfromInteger :: Integer -> UVarInt
fromInteger :: Integer -> UVarInt
Num, Eq UVarInt
UVarInt
Eq UVarInt =>
(UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> UVarInt
-> (Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> Bool)
-> (UVarInt -> Maybe Int)
-> (UVarInt -> Int)
-> (UVarInt -> Bool)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int -> UVarInt)
-> (UVarInt -> Int)
-> Bits UVarInt
Int -> UVarInt
UVarInt -> Bool
UVarInt -> Int
UVarInt -> Maybe Int
UVarInt -> UVarInt
UVarInt -> Int -> Bool
UVarInt -> Int -> UVarInt
UVarInt -> UVarInt -> UVarInt
forall a.
Eq a =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
$c.&. :: UVarInt -> UVarInt -> UVarInt
.&. :: UVarInt -> UVarInt -> UVarInt
$c.|. :: UVarInt -> UVarInt -> UVarInt
.|. :: UVarInt -> UVarInt -> UVarInt
$cxor :: UVarInt -> UVarInt -> UVarInt
xor :: UVarInt -> UVarInt -> UVarInt
$ccomplement :: UVarInt -> UVarInt
complement :: UVarInt -> UVarInt
$cshift :: UVarInt -> Int -> UVarInt
shift :: UVarInt -> Int -> UVarInt
$crotate :: UVarInt -> Int -> UVarInt
rotate :: UVarInt -> Int -> UVarInt
$czeroBits :: UVarInt
zeroBits :: UVarInt
$cbit :: Int -> UVarInt
bit :: Int -> UVarInt
$csetBit :: UVarInt -> Int -> UVarInt
setBit :: UVarInt -> Int -> UVarInt
$cclearBit :: UVarInt -> Int -> UVarInt
clearBit :: UVarInt -> Int -> UVarInt
$ccomplementBit :: UVarInt -> Int -> UVarInt
complementBit :: UVarInt -> Int -> UVarInt
$ctestBit :: UVarInt -> Int -> Bool
testBit :: UVarInt -> Int -> Bool
$cbitSizeMaybe :: UVarInt -> Maybe Int
bitSizeMaybe :: UVarInt -> Maybe Int
$cbitSize :: UVarInt -> Int
bitSize :: UVarInt -> Int
$cisSigned :: UVarInt -> Bool
isSigned :: UVarInt -> Bool
$cshiftL :: UVarInt -> Int -> UVarInt
shiftL :: UVarInt -> Int -> UVarInt
$cunsafeShiftL :: UVarInt -> Int -> UVarInt
unsafeShiftL :: UVarInt -> Int -> UVarInt
$cshiftR :: UVarInt -> Int -> UVarInt
shiftR :: UVarInt -> Int -> UVarInt
$cunsafeShiftR :: UVarInt -> Int -> UVarInt
unsafeShiftR :: UVarInt -> Int -> UVarInt
$crotateL :: UVarInt -> Int -> UVarInt
rotateL :: UVarInt -> Int -> UVarInt
$crotateR :: UVarInt -> Int -> UVarInt
rotateR :: UVarInt -> Int -> UVarInt
$cpopCount :: UVarInt -> Int
popCount :: UVarInt -> Int
Bits, Int -> UVarInt
UVarInt -> Int
UVarInt -> [UVarInt]
UVarInt -> UVarInt
UVarInt -> UVarInt -> [UVarInt]
UVarInt -> UVarInt -> UVarInt -> [UVarInt]
(UVarInt -> UVarInt)
-> (UVarInt -> UVarInt)
-> (Int -> UVarInt)
-> (UVarInt -> Int)
-> (UVarInt -> [UVarInt])
-> (UVarInt -> UVarInt -> [UVarInt])
-> (UVarInt -> UVarInt -> [UVarInt])
-> (UVarInt -> UVarInt -> UVarInt -> [UVarInt])
-> Enum UVarInt
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: UVarInt -> UVarInt
succ :: UVarInt -> UVarInt
$cpred :: UVarInt -> UVarInt
pred :: UVarInt -> UVarInt
$ctoEnum :: Int -> UVarInt
toEnum :: Int -> UVarInt
$cfromEnum :: UVarInt -> Int
fromEnum :: UVarInt -> Int
$cenumFrom :: UVarInt -> [UVarInt]
enumFrom :: UVarInt -> [UVarInt]
$cenumFromThen :: UVarInt -> UVarInt -> [UVarInt]
enumFromThen :: UVarInt -> UVarInt -> [UVarInt]
$cenumFromTo :: UVarInt -> UVarInt -> [UVarInt]
enumFromTo :: UVarInt -> UVarInt -> [UVarInt]
$cenumFromThenTo :: UVarInt -> UVarInt -> UVarInt -> [UVarInt]
enumFromThenTo :: UVarInt -> UVarInt -> UVarInt -> [UVarInt]
Enum, Eq UVarInt
Eq UVarInt =>
(UVarInt -> UVarInt -> Ordering)
-> (UVarInt -> UVarInt -> Bool)
-> (UVarInt -> UVarInt -> Bool)
-> (UVarInt -> UVarInt -> Bool)
-> (UVarInt -> UVarInt -> Bool)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> Ord UVarInt
UVarInt -> UVarInt -> Bool
UVarInt -> UVarInt -> Ordering
UVarInt -> UVarInt -> UVarInt
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UVarInt -> UVarInt -> Ordering
compare :: UVarInt -> UVarInt -> Ordering
$c< :: UVarInt -> UVarInt -> Bool
< :: UVarInt -> UVarInt -> Bool
$c<= :: UVarInt -> UVarInt -> Bool
<= :: UVarInt -> UVarInt -> Bool
$c> :: UVarInt -> UVarInt -> Bool
> :: UVarInt -> UVarInt -> Bool
$c>= :: UVarInt -> UVarInt -> Bool
>= :: UVarInt -> UVarInt -> Bool
$cmax :: UVarInt -> UVarInt -> UVarInt
max :: UVarInt -> UVarInt -> UVarInt
$cmin :: UVarInt -> UVarInt -> UVarInt
min :: UVarInt -> UVarInt -> UVarInt
Ord, Num UVarInt
Ord UVarInt
(Num UVarInt, Ord UVarInt) => (UVarInt -> Rational) -> Real UVarInt
UVarInt -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: UVarInt -> Rational
toRational :: UVarInt -> Rational
Real, Enum UVarInt
Real UVarInt
(Real UVarInt, Enum UVarInt) =>
(UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> UVarInt)
-> (UVarInt -> UVarInt -> (UVarInt, UVarInt))
-> (UVarInt -> UVarInt -> (UVarInt, UVarInt))
-> (UVarInt -> Integer)
-> Integral UVarInt
UVarInt -> Integer
UVarInt -> UVarInt -> (UVarInt, UVarInt)
UVarInt -> UVarInt -> UVarInt
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: UVarInt -> UVarInt -> UVarInt
quot :: UVarInt -> UVarInt -> UVarInt
$crem :: UVarInt -> UVarInt -> UVarInt
rem :: UVarInt -> UVarInt -> UVarInt
$cdiv :: UVarInt -> UVarInt -> UVarInt
div :: UVarInt -> UVarInt -> UVarInt
$cmod :: UVarInt -> UVarInt -> UVarInt
mod :: UVarInt -> UVarInt -> UVarInt
$cquotRem :: UVarInt -> UVarInt -> (UVarInt, UVarInt)
quotRem :: UVarInt -> UVarInt -> (UVarInt, UVarInt)
$cdivMod :: UVarInt -> UVarInt -> (UVarInt, UVarInt)
divMod :: UVarInt -> UVarInt -> (UVarInt, UVarInt)
$ctoInteger :: UVarInt -> Integer
toInteger :: UVarInt -> Integer
Integral, UVarInt
UVarInt -> UVarInt -> Bounded UVarInt
forall a. a -> a -> Bounded a
$cminBound :: UVarInt
minBound :: UVarInt
$cmaxBound :: UVarInt
maxBound :: UVarInt
Bounded, UVarInt -> ()
(UVarInt -> ()) -> NFData UVarInt
forall a. (a -> ()) -> NFData a
$crnf :: UVarInt -> ()
rnf :: UVarInt -> ()
NFData)
major, minor, patch :: UVarInt
major :: UVarInt
major = case Version -> [Int]
versionBranch Version
version of (Int
x:[Int]
_) -> Int -> UVarInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x; [Int]
_ -> UVarInt
0
minor :: UVarInt
minor = case Version -> [Int]
versionBranch Version
version of (Int
_:Int
x:[Int]
_) -> Int -> UVarInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x; [Int]
_ -> UVarInt
0
patch :: UVarInt
patch = case Version -> [Int]
versionBranch Version
version of (Int
_:Int
_:Int
x:[Int]
_) -> Int -> UVarInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x; [Int]
_ -> UVarInt
0
clientName :: ChString
clientName :: ChString
clientName = String -> ChString
forall a. IsString a => String -> a
fromString (String -> ChString) -> String -> ChString
forall a b. (a -> b) -> a -> b
$
String
"ClickHaskell-" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UVarInt -> String
forall a. Show a => a -> String
show UVarInt
major String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UVarInt -> String
forall a. Show a => a -> String
show UVarInt
minor String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> UVarInt -> String
forall a. Show a => a -> String
show UVarInt
patch
newtype ProtocolRevision = MkProtocolRevision UVarInt
deriving newtype (ProtocolRevision -> ProtocolRevision -> Bool
(ProtocolRevision -> ProtocolRevision -> Bool)
-> (ProtocolRevision -> ProtocolRevision -> Bool)
-> Eq ProtocolRevision
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProtocolRevision -> ProtocolRevision -> Bool
== :: ProtocolRevision -> ProtocolRevision -> Bool
$c/= :: ProtocolRevision -> ProtocolRevision -> Bool
/= :: ProtocolRevision -> ProtocolRevision -> Bool
Eq, Integer -> ProtocolRevision
ProtocolRevision -> ProtocolRevision
ProtocolRevision -> ProtocolRevision -> ProtocolRevision
(ProtocolRevision -> ProtocolRevision -> ProtocolRevision)
-> (ProtocolRevision -> ProtocolRevision -> ProtocolRevision)
-> (ProtocolRevision -> ProtocolRevision -> ProtocolRevision)
-> (ProtocolRevision -> ProtocolRevision)
-> (ProtocolRevision -> ProtocolRevision)
-> (ProtocolRevision -> ProtocolRevision)
-> (Integer -> ProtocolRevision)
-> Num ProtocolRevision
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
+ :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
$c- :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
- :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
$c* :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
* :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
$cnegate :: ProtocolRevision -> ProtocolRevision
negate :: ProtocolRevision -> ProtocolRevision
$cabs :: ProtocolRevision -> ProtocolRevision
abs :: ProtocolRevision -> ProtocolRevision
$csignum :: ProtocolRevision -> ProtocolRevision
signum :: ProtocolRevision -> ProtocolRevision
$cfromInteger :: Integer -> ProtocolRevision
fromInteger :: Integer -> ProtocolRevision
Num, Eq ProtocolRevision
Eq ProtocolRevision =>
(ProtocolRevision -> ProtocolRevision -> Ordering)
-> (ProtocolRevision -> ProtocolRevision -> Bool)
-> (ProtocolRevision -> ProtocolRevision -> Bool)
-> (ProtocolRevision -> ProtocolRevision -> Bool)
-> (ProtocolRevision -> ProtocolRevision -> Bool)
-> (ProtocolRevision -> ProtocolRevision -> ProtocolRevision)
-> (ProtocolRevision -> ProtocolRevision -> ProtocolRevision)
-> Ord ProtocolRevision
ProtocolRevision -> ProtocolRevision -> Bool
ProtocolRevision -> ProtocolRevision -> Ordering
ProtocolRevision -> ProtocolRevision -> ProtocolRevision
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ProtocolRevision -> ProtocolRevision -> Ordering
compare :: ProtocolRevision -> ProtocolRevision -> Ordering
$c< :: ProtocolRevision -> ProtocolRevision -> Bool
< :: ProtocolRevision -> ProtocolRevision -> Bool
$c<= :: ProtocolRevision -> ProtocolRevision -> Bool
<= :: ProtocolRevision -> ProtocolRevision -> Bool
$c> :: ProtocolRevision -> ProtocolRevision -> Bool
> :: ProtocolRevision -> ProtocolRevision -> Bool
$c>= :: ProtocolRevision -> ProtocolRevision -> Bool
>= :: ProtocolRevision -> ProtocolRevision -> Bool
$cmax :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
max :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
$cmin :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
min :: ProtocolRevision -> ProtocolRevision -> ProtocolRevision
Ord, ProtocolRevision -> ProtocolRevision -> Builder
(ProtocolRevision -> ProtocolRevision -> Builder)
-> Serializable ProtocolRevision
forall chType.
(ProtocolRevision -> chType -> Builder) -> Serializable chType
$cserialize :: ProtocolRevision -> ProtocolRevision -> Builder
serialize :: ProtocolRevision -> ProtocolRevision -> Builder
Serializable)
{-# INLINE [0] afterRevision #-}
afterRevision
:: forall rev monoid
. (KnownNat rev, Monoid monoid)
=> ProtocolRevision -> monoid -> monoid
afterRevision :: forall (rev :: Nat) monoid.
(KnownNat rev, Monoid monoid) =>
ProtocolRevision -> monoid -> monoid
afterRevision ProtocolRevision
chosenRevision monoid
monoid =
if ProtocolRevision
chosenRevision ProtocolRevision -> ProtocolRevision -> Bool
forall a. Ord a => a -> a -> Bool
>= (Integer -> ProtocolRevision
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ProtocolRevision)
-> (Proxy rev -> Integer) -> Proxy rev -> ProtocolRevision
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy rev -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal) (forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @rev)
then monoid
monoid
else monoid
forall a. Monoid a => a
mempty
latestSupportedRevision :: ProtocolRevision
latestSupportedRevision :: ProtocolRevision
latestSupportedRevision = (Integer -> ProtocolRevision
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ProtocolRevision)
-> (Proxy DBMS_TCP_PROTOCOL_VERSION -> Integer)
-> Proxy DBMS_TCP_PROTOCOL_VERSION
-> ProtocolRevision
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy DBMS_TCP_PROTOCOL_VERSION -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal) (forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @DBMS_TCP_PROTOCOL_VERSION)
data SinceRevision a (revisionNumber :: Nat) = MkSinceRevision a | NotPresented
instance
(KnownNat revision, Deserializable chType)
=>
Deserializable (SinceRevision chType revision)
where
deserialize :: ProtocolRevision -> Get (SinceRevision chType revision)
deserialize ProtocolRevision
rev =
if ProtocolRevision
rev ProtocolRevision -> ProtocolRevision -> Bool
forall a. Ord a => a -> a -> Bool
>= (Integer -> ProtocolRevision
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ProtocolRevision)
-> (Proxy revision -> Integer)
-> Proxy revision
-> ProtocolRevision
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy revision -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal) (forall (t :: Nat). Proxy t
forall {k} (t :: k). Proxy t
Proxy @revision)
then chType -> SinceRevision chType revision
forall a (revisionNumber :: Nat).
a -> SinceRevision a revisionNumber
MkSinceRevision (chType -> SinceRevision chType revision)
-> Get chType -> Get (SinceRevision chType revision)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall chType.
Deserializable chType =>
ProtocolRevision -> Get chType
deserialize @chType ProtocolRevision
rev
else SinceRevision chType revision
-> Get (SinceRevision chType revision)
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SinceRevision chType revision
forall a (revisionNumber :: Nat). SinceRevision a revisionNumber
NotPresented
instance
(KnownNat revision, Serializable chType)
=>
Serializable (SinceRevision chType revision)
where
serialize :: ProtocolRevision -> SinceRevision chType revision -> Builder
serialize ProtocolRevision
rev (MkSinceRevision chType
val) = forall (rev :: Nat) monoid.
(KnownNat rev, Monoid monoid) =>
ProtocolRevision -> monoid -> monoid
afterRevision @revision ProtocolRevision
rev (ProtocolRevision -> chType -> Builder
forall chType.
Serializable chType =>
ProtocolRevision -> chType -> Builder
serialize ProtocolRevision
rev chType
val)
serialize ProtocolRevision
rev SinceRevision chType revision
NotPresented = forall (rev :: Nat) monoid.
(KnownNat rev, Monoid monoid) =>
ProtocolRevision -> monoid -> monoid
afterRevision @revision ProtocolRevision
rev (String -> Builder
forall a. HasCallStack => String -> a
error String
"Unexpected error")
type DBMS_TCP_PROTOCOL_VERSION = 54448;
type DBMS_MIN_REVISION_WITH_CLIENT_INFO = 54032;
type DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE = 54058;
type DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO = 54060;
type DBMS_MIN_REVISION_WITH_TABLES_STATUS = 54226;
type DBMS_MIN_REVISION_WITH_TIME_ZONE_PARAMETER_IN_DATETIME_DATA_TYPE = 54337;
type DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME = 54372;
type DBMS_MIN_REVISION_WITH_VERSION_PATCH = 54401;
type DBMS_MIN_REVISION_WITH_SERVER_LOGS = 54406;
type DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD = 54448;
type DBMS_MIN_MAJOR_VERSION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD = 21;
type DBMS_MIN_MINOR_VERSION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD = 4;
type DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA = 54410;
type DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE = 54405;
type DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO = 54420;
type DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS = 54429;
type DBMS_MIN_REVISION_WITH_SCALARS = 54429;
type DBMS_MIN_REVISION_WITH_OPENTELEMETRY = 54442;
type DBMS_MIN_REVISION_WITH_AGGREGATE_FUNCTIONS_VERSIONING = 54452;
type DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION = 1;
type DBMS_MIN_SUPPORTED_PARALLEL_REPLICAS_PROTOCOL_VERSION = 3;
type DBMS_PARALLEL_REPLICAS_MIN_VERSION_WITH_MARK_SEGMENT_SIZE_FIELD = 4;
type DBMS_PARALLEL_REPLICAS_PROTOCOL_VERSION = 4;
type DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS = 54453;
type DBMS_MERGE_TREE_PART_INFO_VERSION = 1;
type DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET = 54441;
type DBMS_MIN_REVISION_WITH_X_FORWARDED_FOR_IN_CLIENT_INFO = 54443;
type DBMS_MIN_REVISION_WITH_REFERER_IN_CLIENT_INFO = 54447;
type DBMS_MIN_PROTOCOL_VERSION_WITH_DISTRIBUTED_DEPTH = 54448;
type DBMS_MIN_PROTOCOL_VERSION_WITH_INCREMENTAL_PROFILE_EVENTS = 54451;
type DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION = 54454;
type DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME = 54449;
type DBMS_MIN_PROTOCOL_VERSION_WITH_PROFILE_EVENTS_IN_INSERT = 54456;
type DBMS_MIN_PROTOCOL_VERSION_WITH_VIEW_IF_PERMITTED = 54457;
type DBMS_MIN_PROTOCOL_VERSION_WITH_ADDENDUM = 54458;
type DBMS_MIN_PROTOCOL_VERSION_WITH_QUOTA_KEY = 54458;
type DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS = 54459;
type DBMS_MIN_PROTOCOL_VERSION_WITH_SERVER_QUERY_TIME_IN_PROGRESS = 54460;
type DBMS_MIN_PROTOCOL_VERSION_WITH_PASSWORD_COMPLEXITY_RULES = 54461;
type DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET_V2 = 54462;
type DBMS_MIN_PROTOCOL_VERSION_WITH_TOTAL_BYTES_IN_PROGRESS = 54463;
type DBMS_MIN_PROTOCOL_VERSION_WITH_TIMEZONE_UPDATES = 54464;
type DBMS_MIN_REVISION_WITH_SPARSE_SERIALIZATION = 54465;
type DBMS_MIN_REVISION_WITH_SSH_AUTHENTICATION = 54466;
type DBMS_MIN_REVISION_WITH_TABLE_READ_ONLY_CHECK = 54467;
type DBMS_MIN_REVISION_WITH_SYSTEM_KEYWORDS_TABLE = 54468;
type DBMS_MIN_REVISION_WITH_ROWS_BEFORE_AGGREGATION = 54469;
type DBMS_MIN_PROTOCOL_VERSION_WITH_CHUNKED_PACKETS = 54470;
type DBMS_MIN_REVISION_WITH_VERSIONED_PARALLEL_REPLICAS_PROTOCOL = 54471;