Constructor
new Client(options)
A Client holds connections to a Cassandra cluster, allowing it to be queried.
Each Client instance maintains multiple connections to the cluster nodes,
provides
policies to choose which node to use for each query,
and handles
retries for failed query (when it makes sense), etc...
Client instances are designed to be long-lived and usually a single instance is enough
per application. As a given Client can only be "logged" into one keyspace at
a time (where the "logged" keyspace is the one used by query if the query doesn't
explicitly use a fully qualified table name), it can make sense to create one
client per keyspace used. This is however not necessary to query multiple keyspaces
since it is always possible to use a single session with fully qualified table name
in queries.
Parameters:
Name |
Type |
Description |
options |
ClientOptions
|
The options for this instance. |
Methods
batch(queries, optionsopt, callback)
Executes batch of queries on an available connection to a host.
Parameters:
Name |
Type |
Attributes |
Description |
queries |
Array.<string>
|
Array.<{query, params}>
|
|
The queries to execute as an Array of strings or as an array of object containing the query and params |
options |
QueryOptions
|
<optional>
|
|
callback |
ResultCallback
|
|
Executes callback(err, result) when the batch was executed |
connect(callback)
Tries to connect to one of the
contactPoints and discover the nodes of the cluster.
If the Client is already connected, it immediately invokes callback.
Parameters:
Name |
Type |
Description |
callback |
function
|
The callback is invoked when the pool is connected
(or at least 1 connected and the rest failed to connect) or it is not possible to connect |
eachRow(query, paramsopt, optionsopt, rowCallback, callbackopt)
Executes the query and calls rowCallback for each row as soon as they are received.
Calls final callback after all rows have been sent, or when there is an error.
The query can be prepared (recommended) or not depending on QueryOptions.prepare flag. Retries on multiple hosts if needed.
Parameters:
Name |
Type |
Attributes |
Description |
query |
String
|
|
The query to execute |
params |
Array
|
Object
|
<optional>
|
Array of parameter values or an associative array (object) containing parameter names as keys and its value |
options |
QueryOptions
|
<optional>
|
|
rowCallback |
function
|
|
Executes rowCallback(n, row) per each row received, where n is the row index and row is the current Row. |
callback |
function
|
<optional>
|
Executes callback(err, totalCount) after all rows have been received. |
execute(query, paramsopt, optionsopt, callback)
Executes a query on an available connection.
The query can be prepared (recommended) or not depending on QueryOptions.prepare flag. Retries on multiple hosts if needed.
Parameters:
Name |
Type |
Attributes |
Description |
query |
String
|
|
The query to execute |
params |
Array
|
Object
|
<optional>
|
Array of parameter values or an associative array (object) containing parameter names as keys and its value |
options |
QueryOptions
|
<optional>
|
|
callback |
ResultCallback
|
|
Executes callback(err, result) when finished |
getReplicas(keyspace, token) → {Array}
Gets the host list representing the replicas that contain such partition.
Parameters:
Name |
Type |
Description |
keyspace |
String
|
|
token |
Buffer
|
|
Returns:
-
Type
-
Array
shutdown(callbackopt)
Closes all connections to all hosts
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
|
stream(query, paramsopt, optionsopt, callbackopt) → {exports.ResultStream}
Executes the query and pushes the rows to the result stream
as soon as they received.
Calls callback after all rows have been sent, or when there is an error.
The stream is a Readable Streams2 object
that contains the raw bytes of the field value.
It can be piped downstream and provides automatic pause/resume logic (it buffers when not read).
The query can be prepared (recommended) or not depending on QueryOptions.prepare flag. Retries on multiple hosts if needed.
Parameters:
Name |
Type |
Attributes |
Description |
query |
String
|
|
The query to prepare and execute |
params |
Array
|
Object
|
<optional>
|
Array of parameter values or an associative array (object) containing parameter names as keys and its value |
options |
QueryOptions
|
<optional>
|
|
callback |
function
|
<optional>
|
executes callback(err) after all rows have been received or if there is an error |
Returns:
-
Type
-
exports.ResultStream