Safe Haskell | None |
---|---|
Language | Haskell2010 |
Like Database.CQL.Protocol but exports the whole encode/decode machinery for all types.
- class Cql a where
- newtype Keyspace = Keyspace {
- unKeyspace :: Text
- newtype Table = Table {}
- newtype PagingState = PagingState {}
- newtype QueryId k a b = QueryId {}
- newtype QueryString k a b = QueryString {}
- data Version
- data CqlVersion
- = Cqlv300
- | CqlVersion !Text
- data CompressionAlgorithm
- data Compression = Compression {
- algorithm :: !CompressionAlgorithm
- shrink :: ByteString -> Maybe ByteString
- expand :: ByteString -> Maybe ByteString
- noCompression :: Compression
- data Consistency
- = Any
- | One
- | Two
- | Three
- | Quorum
- | All
- | LocalQuorum
- | EachQuorum
- | Serial
- | LocalOne
- | LocalSerial
- data OpCode
- data ColumnType
- = CustomColumn !Text
- | AsciiColumn
- | BigIntColumn
- | BlobColumn
- | BooleanColumn
- | CounterColumn
- | DecimalColumn
- | DoubleColumn
- | FloatColumn
- | IntColumn
- | TextColumn
- | TimestampColumn
- | UuidColumn
- | VarCharColumn
- | VarIntColumn
- | TimeUuidColumn
- | InetColumn
- | MaybeColumn !ColumnType
- | ListColumn !ColumnType
- | SetColumn !ColumnType
- | MapColumn !ColumnType !ColumnType
- | TupleColumn [ColumnType]
- | UdtColumn !Keyspace !Text [(Text, ColumnType)]
- newtype Ascii = Ascii {}
- newtype Blob = Blob {}
- newtype Counter = Counter {
- fromCounter :: Int64
- newtype TimeUuid = TimeUuid {
- fromTimeUuid :: UUID
- newtype Set a = Set {
- fromSet :: [a]
- newtype Map a b = Map {
- fromMap :: [(a, b)]
- data Value
- = CqlCustom !ByteString
- | CqlBoolean !Bool
- | CqlInt !Int32
- | CqlBigInt !Int64
- | CqlVarInt !Integer
- | CqlFloat !Float
- | CqlDecimal !Decimal
- | CqlDouble !Double
- | CqlText !Text
- | CqlInet !IP
- | CqlUuid !UUID
- | CqlTimestamp !Int64
- | CqlAscii !Text
- | CqlBlob !ByteString
- | CqlCounter !Int64
- | CqlTimeUuid !UUID
- | CqlMaybe (Maybe Value)
- | CqlList [Value]
- | CqlSet [Value]
- | CqlMap [(Value, Value)]
- | CqlTuple [Value]
- | CqlUdt [(Text, Value)]
- newtype Tagged a b = Tagged {
- untag :: b
- retag :: Tagged a c -> Tagged b c
- data R
- data W
- data S
- data Header = Header {
- headerType :: !HeaderType
- version :: !Version
- flags :: !Flags
- streamId :: !StreamId
- opCode :: !OpCode
- bodyLength :: !Length
- data HeaderType
- header :: Version -> ByteString -> Either String Header
- encodeHeader :: Version -> HeaderType -> Flags -> StreamId -> OpCode -> Length -> PutM ()
- decodeHeader :: Version -> Get Header
- newtype Length = Length {
- lengthRepr :: Int32
- encodeLength :: Putter Length
- decodeLength :: Get Length
- data StreamId
- mkStreamId :: Integral i => i -> StreamId
- fromStreamId :: StreamId -> Int
- encodeStreamId :: Version -> Putter StreamId
- decodeStreamId :: Version -> Get StreamId
- data Flags
- compress :: Flags
- tracing :: Flags
- isSet :: Flags -> Flags -> Bool
- encodeFlags :: Putter Flags
- decodeFlags :: Get Flags
- data Request k a b
- pack :: Tuple a => Version -> Compression -> Bool -> StreamId -> Request k a b -> Either String ByteString
- encodeRequest :: Tuple a => Version -> Putter (Request k a b)
- getOpCode :: Request k a b -> OpCode
- data Options = Options
- encodeOptions :: Putter Options
- data Startup = Startup !CqlVersion !CompressionAlgorithm
- encodeStartup :: Putter Startup
- newtype AuthResponse = AuthResponse ByteString
- encodeAuthResponse :: Putter AuthResponse
- newtype Register = Register [EventType]
- data EventType
- encodeRegister :: Putter Register
- encodeEventType :: Putter EventType
- data Query k a b = Query !(QueryString k a b) !(QueryParams a)
- data QueryParams a = QueryParams {}
- data SerialConsistency
- encodeQuery :: Tuple a => Version -> Putter (Query k a b)
- encodeQueryParams :: forall a. Tuple a => Version -> Putter (QueryParams a)
- data Batch = Batch {}
- data BatchQuery where
- BatchQuery :: (Show a, Tuple a, Tuple b) => !(QueryString W a b) -> !a -> BatchQuery
- BatchPrepared :: (Show a, Tuple a, Tuple b) => !(QueryId W a b) -> !a -> BatchQuery
- data BatchType
- encodeBatch :: Version -> Putter Batch
- encodeBatchType :: Putter BatchType
- encodeBatchQuery :: Version -> Putter BatchQuery
- newtype Prepare k a b = Prepare (QueryString k a b)
- encodePrepare :: Putter (Prepare k a b)
- data Execute k a b = Execute !(QueryId k a b) !(QueryParams a)
- encodeExecute :: Tuple a => Version -> Putter (Execute k a b)
- data Response k a b
- = RsError (Maybe UUID) !Error
- | RsReady (Maybe UUID) !Ready
- | RsAuthenticate (Maybe UUID) !Authenticate
- | RsAuthChallenge (Maybe UUID) !AuthChallenge
- | RsAuthSuccess (Maybe UUID) !AuthSuccess
- | RsSupported (Maybe UUID) !Supported
- | RsResult (Maybe UUID) !(Result k a b)
- | RsEvent (Maybe UUID) !Event
- unpack :: (Tuple a, Tuple b) => Compression -> Header -> ByteString -> Either String (Response k a b)
- data Ready = Ready
- decodeReady :: Get Ready
- newtype Authenticate = Authenticate Text
- newtype AuthChallenge = AuthChallenge (Maybe ByteString)
- newtype AuthSuccess = AuthSuccess (Maybe ByteString)
- decodeAuthenticate :: Get Authenticate
- decodeAuthChallenge :: Get AuthChallenge
- decodeAuthSuccess :: Get AuthSuccess
- data Result k a b
- = VoidResult
- | RowsResult !MetaData [b]
- | SetKeyspaceResult !Keyspace
- | PreparedResult !(QueryId k a b) !MetaData !MetaData
- | SchemaChangeResult !SchemaChange
- data MetaData = MetaData {
- columnCount :: !Int32
- pagingState :: Maybe PagingState
- columnSpecs :: [ColumnSpec]
- data ColumnSpec = ColumnSpec {
- keyspace :: !Keyspace
- table :: !Table
- columnName :: !Text
- columnType :: !ColumnType
- decodeResult :: forall k a b. (Tuple a, Tuple b) => Version -> Get (Result k a b)
- decodeMetaData :: Get MetaData
- data Supported = Supported [CompressionAlgorithm] [CqlVersion]
- decodeSupported :: Get Supported
- data Event
- data TopologyChange
- data SchemaChange
- data StatusChange
- data Change
- decodeSchemaChange :: Version -> Get SchemaChange
- decodeChange :: Version -> Get Change
- decodeEvent :: Version -> Get Event
- decodeTopologyChange :: Get TopologyChange
- decodeStatusChange :: Get StatusChange
- data Error
- = AlreadyExists !Text !Keyspace !Table
- | BadCredentials !Text
- | ConfigError !Text
- | Invalid !Text
- | IsBootstrapping !Text
- | Overloaded !Text
- | ProtocolError !Text
- | ServerError !Text
- | SyntaxError !Text
- | TruncateError !Text
- | Unauthorized !Text
- | Unprepared !Text !ByteString
- | Unavailable { }
- | ReadTimeout { }
- | WriteTimeout { }
- data WriteType
- decodeError :: Get Error
- decodeWriteType :: Get WriteType
- class PrivateTuple a => Tuple a
- count :: PrivateTuple a => Tagged a Int
- check :: PrivateTuple a => Tagged a ([ColumnType] -> [ColumnType])
- tuple :: PrivateTuple a => Version -> [ColumnType] -> Get a
- store :: PrivateTuple a => Version -> Putter a
- data Row
- mkRow :: [(Value, ColumnType)] -> Row
- fromRow :: Cql a => Int -> Row -> Either String a
- columnTypes :: Row -> [ColumnType]
- rowLength :: Row -> Int
- class Record a where
- type family TupleType a
- recordInstance :: Name -> Q [Dec]
- encodeByte :: Putter Word8
- decodeByte :: Get Word8
- encodeSignedByte :: Putter Int8
- decodeSignedByte :: Get Int8
- encodeShort :: Putter Word16
- decodeShort :: Get Word16
- encodeSignedShort :: Putter Int16
- decodeSignedShort :: Get Int16
- encodeInt :: Putter Int32
- decodeInt :: Get Int32
- encodeString :: Putter Text
- decodeString :: Get Text
- encodeLongString :: Putter Text
- decodeLongString :: Get Text
- encodeBytes :: Putter ByteString
- decodeBytes :: Get (Maybe ByteString)
- encodeShortBytes :: Putter ByteString
- decodeShortBytes :: Get ByteString
- encodeUUID :: Putter UUID
- decodeUUID :: Get UUID
- encodeList :: Putter [Text]
- decodeList :: Get [Text]
- encodeMap :: Putter [(Text, Text)]
- decodeMap :: Get [(Text, Text)]
- encodeMultiMap :: Putter [(Text, [Text])]
- decodeMultiMap :: Get [(Text, [Text])]
- encodeSockAddr :: Putter SockAddr
- decodeSockAddr :: Get SockAddr
- encodeConsistency :: Putter Consistency
- decodeConsistency :: Get Consistency
- encodeOpCode :: Putter OpCode
- decodeOpCode :: Get OpCode
- encodeColumnType :: Putter ColumnType
- decodeColumnType :: Get ColumnType
- encodePagingState :: Putter PagingState
- decodePagingState :: Get (Maybe PagingState)
- decodeKeyspace :: Get Keyspace
- decodeTable :: Get Table
- decodeQueryId :: Get (QueryId k a b)
- putValue :: Version -> Putter Value
- getValue :: Version -> ColumnType -> Get Value
Cql type-class
A type that can be converted from and to some CQL Value
.
This type-class is used to map custom types to Cassandra data-types. For example:
newtype MyType = MyType Int32 instance Cql MyType where ctype = Tagged IntColumn toCql (MyType i) = CqlInt i fromCql (CqlInt i) = Right (MyType i) fromCql _ = Left "Expected CqlInt"
ctype :: Tagged a ColumnType Source
the column-type of a
map a
to some CQL data-type
fromCql :: Value -> Either String a Source
map a CQL value back to a
Cql Bool Source | |
Cql Double Source | |
Cql Float Source | |
Cql Int32 Source | |
Cql Int64 Source | |
Cql Integer Source | |
Cql Decimal Source | |
Cql IP Source | |
Cql Text Source | |
Cql UTCTime Source | |
Cql UUID Source | |
Cql TimeUuid Source | |
Cql Counter Source | |
Cql Blob Source | |
Cql Ascii Source | |
Cql a => Cql [a] Source | |
Cql a => Cql (Maybe a) Source | Please note that due to the fact that Cassandra internally represents
empty collection type values (i.e. lists, maps and sets) as |
Cql a => Cql (Set a) Source | |
(Cql a, Cql b) => Cql (Map a b) Source |
Basic type definitions
newtype PagingState Source
Opaque token passed to the server to continue result paging.
ID representing a prepared query.
newtype QueryString k a b Source
Eq (QueryString k a b) Source | |
Show (QueryString k a b) Source | |
IsString (QueryString k a b) Source |
CQL binary protocol version.
data CqlVersion Source
The CQL version (not the binary protocol version).
data Compression Source
Compression | |
|
data Consistency Source
Consistency level.
An opcode is a tag to distinguish protocol frame bodies.
data ColumnType Source
The type of a single CQL column.
A CQL value. The various constructors correspond to CQL data-types for individual columns in Cassandra.
CqlCustom !ByteString | |
CqlBoolean !Bool | |
CqlInt !Int32 | |
CqlBigInt !Int64 | |
CqlVarInt !Integer | |
CqlFloat !Float | |
CqlDecimal !Decimal | |
CqlDouble !Double | |
CqlText !Text | |
CqlInet !IP | |
CqlUuid !UUID | |
CqlTimestamp !Int64 | |
CqlAscii !Text | |
CqlBlob !ByteString | |
CqlCounter !Int64 | |
CqlTimeUuid !UUID | |
CqlMaybe (Maybe Value) | |
CqlList [Value] | |
CqlSet [Value] | |
CqlMap [(Value, Value)] | |
CqlTuple [Value] | binary protocol version >= 3 |
CqlUdt [(Text, Value)] | binary protocol version >= 3 |
Header
Protocol frame header.
Header | |
|
data HeaderType Source
header :: Version -> ByteString -> Either String Header Source
Deserialise a frame header using the version specific decoding format.
encodeHeader :: Version -> HeaderType -> Flags -> StreamId -> OpCode -> Length -> PutM () Source
decodeHeader :: Version -> Get Header Source
Length
The type denoting a protocol frame length.
StreamId
Streams allow multiplexing of requests over a single communication
channel. The StreamId
correlates Request
s with Response
s.
mkStreamId :: Integral i => i -> StreamId Source
fromStreamId :: StreamId -> Int Source
Convert the stream ID to an integer.
decodeStreamId :: Version -> Get StreamId Source
Flags
Type representing header flags. Flags form a monoid and can be used
as in compress <> tracing <> mempty
.
Tracing flag. If a request support tracing and the tracing flag was set, the response to this request will have the tracing flag set and contain tracing information.
Request
The type corresponding to the protocol request frame.
The type parameter k
denotes the kind of request. It is present to allow
distinguishing read operations from write operations. Use R
for read,
W
for write and S
for schema related operations.
a
represents the argument type and b
the return type of this request.
:: Tuple a | |
=> Version | protocol version, which determines the encoding |
-> Compression | compression to use |
-> Bool | enable/disable tracing |
-> StreamId | the stream Id to use |
-> Request k a b | the actual request to serialise |
-> Either String ByteString |
Options
An options request, send prior to Startup
to request the server's
startup options.
Startup
A startup request which is used when initialising a connection to the server. It specifies the CQL version to use and optionally the compression algorithm.
Auth Response
newtype AuthResponse Source
A request send in response to a previous authentication challenge.
Register
Register's the connection this request is made through, to receive server events.
Event types to register.
TopologyChangeEvent | events related to change in the cluster topology |
StatusChangeEvent | events related to change of node status |
SchemaChangeEvent | events related to schema change |
Query
A CQL query (select, insert, etc.).
Query !(QueryString k a b) !(QueryParams a) |
data QueryParams a Source
Query parameters.
QueryParams | |
|
Show a => Show (QueryParams a) Source |
data SerialConsistency Source
Consistency level for the serial phase of conditional updates.
encodeQueryParams :: forall a. Tuple a => Version -> Putter (QueryParams a) Source
Batch
Allows executing a list of queries (prepared or not) as a batch.
data BatchQuery where Source
A GADT to unify queries and prepared queries both of which can be used in batch requests.
BatchQuery :: (Show a, Tuple a, Tuple b) => !(QueryString W a b) -> !a -> BatchQuery | |
BatchPrepared :: (Show a, Tuple a, Tuple b) => !(QueryId W a b) -> !a -> BatchQuery |
BatchLogged | default, uses a batch log for atomic application |
BatchUnLogged | skip the batch log |
BatchCounter | used for batched counter updates |
encodeBatch :: Version -> Putter Batch Source
Prepare
Prepare a query for later execution (cf. Execute
).
Prepare (QueryString k a b) |
encodePrepare :: Putter (Prepare k a b) Source
Execute
Executes a prepared query.
Execute !(QueryId k a b) !(QueryParams a) |
Response
The type corresponding to the protocol response frame.
The type parameter k
denotes the kind of response. It is present to allow
distinguishing read operations from write operations. Use R
for read,
W
for write and S
for schema related operations.
a
represents the argument type and b
the return type of this
response.
RsError (Maybe UUID) !Error | |
RsReady (Maybe UUID) !Ready | |
RsAuthenticate (Maybe UUID) !Authenticate | |
RsAuthChallenge (Maybe UUID) !AuthChallenge | |
RsAuthSuccess (Maybe UUID) !AuthSuccess | |
RsSupported (Maybe UUID) !Supported | |
RsResult (Maybe UUID) !(Result k a b) | |
RsEvent (Maybe UUID) !Event |
unpack :: (Tuple a, Tuple b) => Compression -> Header -> ByteString -> Either String (Response k a b) Source
Deserialise a Response
from the given ByteString
.
Ready
The server is ready to process queries. Response of a Startup
request.
Authenticate
newtype Authenticate Source
The server requires authentication.
newtype AuthChallenge Source
A server-send authentication challenge.
newtype AuthSuccess Source
Indicates the success of an authentication phase.
Result
Query response.
Part of a RowsResult
. Describes the result set.
MetaData | |
|
data ColumnSpec Source
The column specification. Part of MetaData
unless skipMetaData
in
QueryParams
was True.
ColumnSpec | |
|
Supported
The startup options supported by the server. Response of an Options
request.
Event
Messages send by the server without request, if the connection has
been Register
ed to receive such events.
data TopologyChange Source
data SchemaChange Source
data StatusChange Source
decodeChange :: Version -> Get Change Source
decodeEvent :: Version -> Get Event Source
Error
Error response.
Tuple and Record
check :: PrivateTuple a => Tagged a ([ColumnType] -> [ColumnType]) Source
tuple :: PrivateTuple a => Version -> [ColumnType] -> Get a Source
mkRow :: [(Value, ColumnType)] -> Row Source
columnTypes :: Row -> [ColumnType] Source
Record/Tuple conversion. For example:
data Peer = Peer { peerAddr :: IP , peerRPC :: IP , peerDC :: Text , peerRack :: Text } deriving Show recordInstance ''Peer map asRecord <$> performQuery "SELECT peer, rpc_address, data_center, rack FROM system.peers"
The generated type-class instance maps between record and tuple constructors:
type instance TupleType Peer = (IP, IP, Text, Text) instance Record Peer where asTuple (Peer a b c d) = (a, b, c, d) asRecord (a, b, c, d) = Peer a b c d
recordInstance :: Name -> Q [Dec] Source
Codec
decodeByte :: Get Word8 Source
decodeBytes :: Get (Maybe ByteString) Source
decodeUUID :: Get UUID Source
encodeList :: Putter [Text] Source
decodeList :: Get [Text] Source
encodeMultiMap :: Putter [(Text, [Text])] Source
decodeMultiMap :: Get [(Text, [Text])] Source
decodeQueryId :: Get (QueryId k a b) Source