Module: Cql::Client
- Defined in:
- lib/cql/client.rb,
lib/cql/client/batch.rb,
lib/cql/client/client.rb,
lib/cql/client/connector.rb,
lib/cql/client/null_logger.rb,
lib/cql/client/void_result.rb,
lib/cql/client/query_result.rb,
lib/cql/client/peer_discovery.rb,
lib/cql/client/request_runner.rb,
lib/cql/client/column_metadata.rb,
lib/cql/client/result_metadata.rb,
lib/cql/client/keyspace_changer.rb,
lib/cql/client/connection_manager.rb,
lib/cql/client/prepared_statement.rb,
lib/cql/client/execute_options_decoder.rb
Overview
A CQL client manages connections to one or more Cassandra nodes and you use it run queries, insert and update data.
Client instances are threadsafe.
See Client for the full client API, or Client.connect for the options available when connecting.
Defined Under Namespace
Classes: Batch, Client, ColumnMetadata, PreparedStatement, PreparedStatementBatch, QueryResult, ResultMetadata, VoidResult
Constant Summary collapse
- InvalidKeyspaceNameError =
Class.new(ClientError)
Class Method Summary collapse
-
.connect(options = {}) ⇒ Cql::Client::Client
Create a new client and connect to Cassandra.
Instance Method Summary collapse
-
#add(*bound_values) ⇒ nil
Add the statement to the batch with the specified bound values.
-
#batch(type = :logged, options = {}) {|batch| ... } ⇒ Cql::Client::VoidResult, Cql::Client::Batch
Yields a batch when called with a block.
-
#close ⇒ Cql::Client
Disconnect from all nodes.
-
#connected? ⇒ true, false
Returns whether or not the client is connected.
-
#execute(cql, *values, options = {}) ⇒ nil, ...
Execute a CQL statement, optionally passing bound values.
-
#keyspace ⇒ String
Returns the name of the current keyspace, or
nil
if no keyspace has been set yet. -
#prepare(cql) ⇒ Cql::Client::PreparedStatement
Returns a prepared statement that can be run over and over again with different bound values.
-
#use(keyspace) ⇒ nil
Changes keyspace by sending a
USE
statement to all connections.
Class Method Details
.connect(options = {}) ⇒ Cql::Client::Client
Create a new client and connect to Cassandra.
By default the client will connect to localhost port 9042, which can be
overridden with the :hosts
and :port
options, respectively. Once
connected to the hosts given in :hosts
the rest of the nodes in the
cluster will automatically be discovered and connected to.
If you have a multi data center setup the client will connect to all nodes
in the data centers where the nodes you pass to :hosts
are located. So
if you only want to connect to nodes in one data center, make sure that
you only specify nodes in that data center in :hosts
.
The connection will succeed if at least one node is up and accepts the connection. Nodes that don't respond within the specified timeout, or where the connection initialization fails for some reason, are ignored.
133 134 135 |
# File 'lib/cql/client.rb', line 133 def self.connect(={}) SynchronousClient.new(AsynchronousClient.new()).connect end |
Instance Method Details
#add(*bound_values) ⇒ nil
Add the statement to the batch with the specified bound values.
|
# File 'lib/cql/client/batch.rb', line 13
|
#batch(type = :logged, options = {}) {|batch| ... } ⇒ Cql::Client::VoidResult, Cql::Client::Batch
Yields a batch when called with a block. The batch is automatically executed at the end of the block and the result is returned.
Returns a batch when called wihtout a block. The batch will remember the options given and merge these with any additional options given when Cql::Client::Batch#execute is called.
Please note that the batch object returned by this method is not thread safe.
The type parameter can be ommitted and the options can then be given as first parameter.
|
# File 'lib/cql/client/client.rb', line 165
|
#connected? ⇒ true, false
Returns whether or not the client is connected.
|
# File 'lib/cql/client/client.rb', line 34
|
#execute(cql, *values, options = {}) ⇒ nil, ...
Execute a CQL statement, optionally passing bound values.
When passing bound values the request encoder will have to guess what
types to encode the values as. For most types this will be no problem,
but for integers and floating point numbers the larger size will be
chosen (e.g. BIGINT
and DOUBLE
and not INT
and FLOAT
). You can
override the guessing with the :type_hint
option. Don't use on-the-fly
bound values when you will issue the request multiple times, prepared
statements are almost always a better choice.
Please note that on-the-fly bound values are only supported by Cassandra 2.0 and above.
|
# File 'lib/cql/client/batch.rb', line 34
|
#keyspace ⇒ String
Returns the name of the current keyspace, or nil
if no keyspace has been
set yet.
|
# File 'lib/cql/client/client.rb', line 40
|
#prepare(cql) ⇒ Cql::Client::PreparedStatement
Returns a prepared statement that can be run over and over again with different bound values.
|
# File 'lib/cql/client/client.rb', line 150
|
#use(keyspace) ⇒ nil
Changes keyspace by sending a USE
statement to all connections.
The the second parameter is meant for internal use only.
|
# File 'lib/cql/client/client.rb', line 47
|