Public Types | |
enum | ConnectionOptions { ConnectToFirstNodeAlways, ConnectToLastAccessedNode, ConnectToRandomNode } |
Public Member Functions | |
Client () | |
void | clearDefaultSchema () |
std::vector< Node > | clusterNodes () |
bool | connect (const std::string &url) |
bool | connect (const Node &node) |
bool | connect (const std::vector< Node > &nodes, ConnectionOptions options=ConnectToLastAccessedNode) |
RawResult | createBlobStorage (const std::string &tableName, int shards=-1, int replicas=-1, const std::string &path=std::string()) |
RawResult | createBlobStorage (const std::string &tableName, const std::string &path) |
const std::string & | defaultSchema () const |
BlobResult | deleteBlob (const std::string &tableName, const std::string &key) |
void | disconnect () |
BlobResult | downloadBlob (const std::string &tableName, const std::string &key, std::ostream &data) |
Result | exec (const std::string &sql) |
Result | exec (const Query &query) |
RawResult | execRaw (const std::string &sql) |
RawResult | execRaw (const Query &query) |
BlobResult | existsBlob (const std::string &tableName, const std::string &key) |
bool | isConnected () const |
operator bool () const | |
bool | refresh (const std::string &table) |
RawResult | removeBlobStorage (const std::string &tableName) |
std::vector< std::string > | schemata () |
void | setDefaultSchema (const std::string &schema) |
BlobResult | uploadBlob (const std::string &tableName, std::istream &data) |
The class Client provides the main interface for accessing to Crate.
To connect to a Crate cluster use connect(). Even tough connecting to a single node is enough CppCrate offers to define multiple nodes that can be used in case of node failure. The exact behavior of using this internal fall back mechanism see Client::ConnectionOptions.
Once connected use exec() or execRaw() to query Crate. While the latter version returns Crate's raw reply the former lets you conveniently access specific reply information. See RawResult and Result for more information. In order to avoid defining the used schema all over the place setDefaultSchema() can be used to minimize the typing effort.
Beside custom queries CppCrate provides some predefined actions that are needed frequently when working with Crate: clusterNodes() for example returns all nodes of the cluster the client is connected to, or refresh() forces Crate to refresh its internal state.
Client also provides an interface for accessing blob data. See createBlobStorage(), uploadBlob(), existsBlob(), downloadBlob(), deleteBlob(), and removeBlobStorage() for more information.
Describes how the client handles node failures. CppCrate's fallback mechanism is only activated on network errors. Error reports issued by Crate are not considered.
CppCrate::Client::Client | ( | ) |
Constructs a not connected client.
void CppCrate::Client::clearDefaultSchema | ( | ) |
Resets the default schema.
std::vector< Node > CppCrate::Client::clusterNodes | ( | ) |
Returns all Crate cluster nodes the client is currently connected to.
bool CppCrate::Client::connect | ( | const std::string & | url | ) |
Connects the client to the Crate cluster node identified by the URL url. This is equivalent to
bool CppCrate::Client::connect | ( | const Node & | node | ) |
Connects the client to the Crate cluster node node.
bool CppCrate::Client::connect | ( | const std::vector< Node > & | nodes, |
ConnectionOptions | options = ConnectToLastAccessedNode |
||
) |
Connects the client to the Crate cluster using the provided Crate cluster nodes nodes. Which node is used is defined by options.
RawResult CppCrate::Client::createBlobStorage | ( | const std::string & | tableName, |
int | shards = -1 , |
||
int | replicas = -1 , |
||
const std::string & | path = std::string() |
||
) |
Creates a new blob table named tableName. Additionally the number of shards and replications can be defined using shards and replicas. If shards or replicas is lesser than 0 it is ignored. If path is set, it is used for the new table's path
.
The returned RawResult can be used to determine if the action was successful.
RawResult CppCrate::Client::createBlobStorage | ( | const std::string & | tableName, |
const std::string & | path | ||
) |
Creates a new blob table named tableName stored at path
.
This is a convenient function for
const std::string & CppCrate::Client::defaultSchema | ( | ) | const |
Returns the default schema.
BlobResult CppCrate::Client::deleteBlob | ( | const std::string & | tableName, |
const std::string & | key | ||
) |
Deletes the blob identified by key of the table tableName and returns the action's result.
void CppCrate::Client::disconnect | ( | ) |
Disconnects the client from the Crate cluster.
BlobResult CppCrate::Client::downloadBlob | ( | const std::string & | tableName, |
const std::string & | key, | ||
std::ostream & | data | ||
) |
Downloads the blob identified by key of the table tableName and stores it to data.
Result CppCrate::Client::exec | ( | const std::string & | sql | ) |
Executes the SQL statement sql and returns the result.
Executes the query query and returns the result.
RawResult CppCrate::Client::execRaw | ( | const std::string & | sql | ) |
Executes the SQL statement sql and returns the raw result.
Executes the query query and returns the raw result.
BlobResult CppCrate::Client::existsBlob | ( | const std::string & | tableName, |
const std::string & | key | ||
) |
Returns whether a blob identified by key exists in the table tableName.
bool CppCrate::Client::isConnected | ( | ) | const |
Returns whether the client is connected.
|
explicit |
Returns whether the client is connected.
bool CppCrate::Client::refresh | ( | const std::string & | table | ) |
Refreshes the table table and returns if the refresh was successful.
RawResult CppCrate::Client::removeBlobStorage | ( | const std::string & | tableName | ) |
Drops the blob table named tableName and returns the corresponding raw result that can be used to determine if the action was successful.
std::vector< std::string > CppCrate::Client::schemata | ( | ) |
Returns all existing schemata.
void CppCrate::Client::setDefaultSchema | ( | const std::string & | schema | ) |
Sets the default schema to schema. This allows SQL statements like
instead of specifying the schema explicitly
BlobResult CppCrate::Client::uploadBlob | ( | const std::string & | tableName, |
std::istream & | data | ||
) |
Uploads data to the table tableName. If the operation was successful the result can be used to receive the key of the inserted blob.