Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
data::cassandra::Handle Class Reference

Represents a handle to the cassandra database cluster. More...

#include <Handle.hpp>

Public Types

using ResultOrErrorType = ResultOrError
 
using MaybeErrorType = MaybeError
 
using FutureWithCallbackType = FutureWithCallback
 
using FutureType = Future
 
using StatementType = Statement
 
using PreparedStatementType = PreparedStatement
 
using ResultType = Result
 

Public Member Functions

 Handle (Settings clusterSettings=Settings::defaultSettings())
 Construct a new handle from a Settings object.
 
 Handle (std::string_view contactPoints)
 Construct a new handle with default settings and only by setting the contact points.
 
 ~Handle ()
 Disconnects gracefully if possible.
 
 Handle (Handle &&)=default
 Move is supported.
 
FutureType asyncConnect () const
 Connect to the cluster asynchronously.
 
MaybeErrorType connect () const
 Synchonous version of the above.
 
FutureType asyncConnect (std::string_view keyspace) const
 Connect to the the specified keyspace asynchronously.
 
MaybeErrorType connect (std::string_view keyspace) const
 Synchonous version of the above.
 
FutureType asyncDisconnect () const
 Disconnect from the cluster asynchronously.
 
MaybeErrorType disconnect () const
 Synchonous version of the above.
 
FutureType asyncReconnect (std::string_view keyspace) const
 Reconnect to the the specified keyspace asynchronously.
 
MaybeErrorType reconnect (std::string_view keyspace) const
 Synchonous version of the above.
 
template<typename... Args>
FutureType asyncExecute (std::string_view query, Args &&... args) const
 Execute a simple query with optional args asynchronously.
 
template<typename... Args>
ResultOrErrorType execute (std::string_view query, Args &&... args) const
 Synchonous version of the above.
 
std::vector< FutureTypeasyncExecuteEach (std::vector< StatementType > const &statements) const
 Execute each of the statements asynchronously.
 
MaybeErrorType executeEach (std::vector< StatementType > const &statements) const
 Synchonous version of the above.
 
template<typename... Args>
FutureType asyncExecute (PreparedStatementType const &statement, Args &&... args) const
 Execute a prepared statement with optional args asynchronously.
 
template<typename... Args>
ResultOrErrorType execute (PreparedStatementType const &statement, Args &&... args) const
 Synchonous version of the above.
 
FutureType asyncExecute (StatementType const &statement) const
 Execute one (bound or simple) statements asynchronously.
 
FutureWithCallbackType asyncExecute (StatementType const &statement, std::function< void(ResultOrErrorType)> &&cb) const
 Execute one (bound or simple) statements asynchronously with a callback.
 
ResultOrErrorType execute (StatementType const &statement) const
 Synchonous version of the above.
 
FutureType asyncExecute (std::vector< StatementType > const &statements) const
 Execute a batch of (bound or simple) statements asynchronously.
 
MaybeErrorType execute (std::vector< StatementType > const &statements) const
 Synchonous version of the above.
 
FutureWithCallbackType asyncExecute (std::vector< StatementType > const &statements, std::function< void(ResultOrErrorType)> &&cb) const
 Execute a batch of (bound or simple) statements asynchronously with a completion callback.
 
PreparedStatementType prepare (std::string_view query) const
 Prepare a statement.
 

Detailed Description

Represents a handle to the cassandra database cluster.

Constructor & Destructor Documentation

◆ Handle() [1/2]

data::cassandra::Handle::Handle ( Settings clusterSettings = Settings::defaultSettings())
explicit

Construct a new handle from a Settings object.

Parameters
clusterSettingsThe settings to use

◆ Handle() [2/2]

data::cassandra::Handle::Handle ( std::string_view contactPoints)
explicit

Construct a new handle with default settings and only by setting the contact points.

Parameters
contactPointsThe contact points to use instead of settings

Member Function Documentation

◆ asyncConnect() [1/2]

Handle::FutureType data::cassandra::Handle::asyncConnect ( ) const
nodiscard

Connect to the cluster asynchronously.

Returns
A future

◆ asyncConnect() [2/2]

Handle::FutureType data::cassandra::Handle::asyncConnect ( std::string_view keyspace) const
nodiscard

Connect to the the specified keyspace asynchronously.

Parameters
keyspaceThe keyspace to use
Returns
A future

◆ asyncDisconnect()

Handle::FutureType data::cassandra::Handle::asyncDisconnect ( ) const
nodiscard

Disconnect from the cluster asynchronously.

Returns
A future

◆ asyncExecute() [1/6]

template<typename... Args>
FutureType data::cassandra::Handle::asyncExecute ( PreparedStatementType const & statement,
Args &&... args ) const
inlinenodiscard

Execute a prepared statement with optional args asynchronously.

Parameters
statementThe prepared statement to execute
argsThe arguments to bind for execution
Returns
A future

◆ asyncExecute() [2/6]

Handle::FutureType data::cassandra::Handle::asyncExecute ( StatementType const & statement) const
nodiscard

Execute one (bound or simple) statements asynchronously.

Parameters
statementThe statement to execute
Returns
A future

◆ asyncExecute() [3/6]

Handle::FutureWithCallbackType data::cassandra::Handle::asyncExecute ( StatementType const & statement,
std::function< void(ResultOrErrorType)> && cb ) const
nodiscard

Execute one (bound or simple) statements asynchronously with a callback.

Parameters
statementThe statement to execute
cbThe callback to execute when data is ready
Returns
A future that holds onto the callback provided

◆ asyncExecute() [4/6]

template<typename... Args>
FutureType data::cassandra::Handle::asyncExecute ( std::string_view query,
Args &&... args ) const
inlinenodiscard

Execute a simple query with optional args asynchronously.

Parameters
queryThe query to execute
argsThe arguments to bind for execution
Returns
A future

◆ asyncExecute() [5/6]

Handle::FutureType data::cassandra::Handle::asyncExecute ( std::vector< StatementType > const & statements) const
nodiscard

Execute a batch of (bound or simple) statements asynchronously.

Parameters
statementsThe statements to execute
Returns
A future

◆ asyncExecute() [6/6]

Handle::FutureWithCallbackType data::cassandra::Handle::asyncExecute ( std::vector< StatementType > const & statements,
std::function< void(ResultOrErrorType)> && cb ) const
nodiscard

Execute a batch of (bound or simple) statements asynchronously with a completion callback.

Parameters
statementsThe statements to execute
cbThe callback to execute when data is ready
Returns
A future that holds onto the callback provided

◆ asyncExecuteEach()

std::vector< Handle::FutureType > data::cassandra::Handle::asyncExecuteEach ( std::vector< StatementType > const & statements) const
nodiscard

Execute each of the statements asynchronously.

Batched version is not always the right option. Especially since it only supports INSERT, UPDATE and DELETE statements. This can be used as an alternative when statements need to execute in bulk.

Parameters
statementsThe statements to execute
Returns
A vector of future objects

◆ asyncReconnect()

Handle::FutureType data::cassandra::Handle::asyncReconnect ( std::string_view keyspace) const
nodiscard

Reconnect to the the specified keyspace asynchronously.

Parameters
keyspaceThe keyspace to use
Returns
A future

◆ connect() [1/2]

Handle::MaybeErrorType data::cassandra::Handle::connect ( ) const
nodiscard

Synchonous version of the above.

See asyncConnect() const for how this works.

Returns
Possibly an error

◆ connect() [2/2]

Handle::MaybeErrorType data::cassandra::Handle::connect ( std::string_view keyspace) const
nodiscard

Synchonous version of the above.

See asyncConnect(std::string_view) const for how this works.

Parameters
keyspaceThe keyspace to use
Returns
Possibly an error

◆ disconnect()

Handle::MaybeErrorType data::cassandra::Handle::disconnect ( ) const

Synchonous version of the above.

See asyncDisconnect() const for how this works.

Returns
Possibly an error

◆ execute() [1/4]

template<typename... Args>
ResultOrErrorType data::cassandra::Handle::execute ( PreparedStatementType const & statement,
Args &&... args ) const
inline

Synchonous version of the above.

See asyncExecute(std::vector<StatementType> const&, Args&&...) const for how this works.

Parameters
statementThe prepared statement to bind and execute
argsThe arguments to bind for execution
Returns
The result or an error

◆ execute() [2/4]

Handle::ResultOrErrorType data::cassandra::Handle::execute ( StatementType const & statement) const

Synchonous version of the above.

See asyncExecute(StatementType const&) const for how this works.

Parameters
statementThe statement to execute
Returns
The result or an error

◆ execute() [3/4]

template<typename... Args>
ResultOrErrorType data::cassandra::Handle::execute ( std::string_view query,
Args &&... args ) const
inline

Synchonous version of the above.

See asyncExecute(std::string_view, Args&&...) const for how this works.

Parameters
queryThe query to execute
argsThe arguments to bind for execution
Returns
The result or an error

◆ execute() [4/4]

Handle::MaybeErrorType data::cassandra::Handle::execute ( std::vector< StatementType > const & statements) const

Synchonous version of the above.

See asyncExecute(std::vector<StatementType> const&) const for how this works.

Parameters
statementsThe statements to execute
Returns
Possibly an error

◆ executeEach()

Handle::MaybeErrorType data::cassandra::Handle::executeEach ( std::vector< StatementType > const & statements) const

Synchonous version of the above.

See asyncExecuteEach(std::vector<StatementType> const&) const for how this works.

Parameters
statementsThe statements to execute
Returns
Possibly an error

◆ prepare()

Handle::PreparedStatementType data::cassandra::Handle::prepare ( std::string_view query) const
nodiscard

Prepare a statement.

Parameters
query
Returns
A prepared statement
Exceptions
std::runtime_errorwith underlying error description on failure

◆ reconnect()

Handle::MaybeErrorType data::cassandra::Handle::reconnect ( std::string_view keyspace) const
nodiscard

Synchonous version of the above.

See asyncReconnect(std::string_view) const for how this works.

Parameters
keyspaceThe keyspace to use
Returns
Possibly an error

The documentation for this class was generated from the following files: