class Client
Represents a database client that maintains multiple connections to the cluster nodes, providing methods to execute CQL statements.
The Client uses policies to decide which nodes to connect to, which node
to use per each query execution, when it should retry failed or timed-out executions and how reconnection to down
nodes should be made.
- Global
- This class is global
Augments
Events
hostAdd
Emitted when a new host is added to the cluster.
-
HostThe host being added.
hostDown
Emitted when a host in the cluster changed status from up to down.
-
hostThe host that changed the status.
hostRemove
Emitted when a host is removed from the cluster
-
HostThe host being removed.
hostUp
Emitted when a host in the cluster changed status from down to up.
-
hostThe host that changed the status.
Members
HostMap hosts
Gets an associative array of cluster hosts.
String keyspace
Gets the name of the active keyspace.
Metadata metadata
Gets the schema and cluster metadata information.
ClientMetrics metrics
The ClientMetrics instance used to expose measurements of its internal
behavior and of the server as seen from the driver side.
By default, a DefaultMetrics instance is used.
Constructor
Client
(ClientOptions options)
Creates a new instance of Client.
Methods
batch
(Array<string> or Array<{query, params}> queries, [QueryOptions options], [ResultCallback callback])
Executes batch of queries on an available connection to a host.
It returns a Promise when a callback is not provided.
connect
([function callback])
Attempts to connect to one of the contactPoints and discovers the rest the nodes of the
cluster.
When the Client is already connected, it resolves immediately.
It returns a Promise when a callback is not provided.
eachRow
(String query, [Array or Object params], [QueryOptions options], function rowCallback, [function callback])
Executes the query and calls rowCallback for each row as soon as they are received. Calls the final
callback after all rows have been sent, or when there is an error.
The query can be prepared (recommended) or not depending on the prepare flag.
Executes a query on an available connection.
The query can be prepared (recommended) or not depending on the prepare flag.
Some execution failures can be handled transparently by the driver, according to the
RetryPolicy or the
SpeculativeExecutionPolicy used.
It returns a Promise when a callback is not provided.
executeGraph
(String query, [Object or null parameters], [GraphQueryOptions or null options], [function callback])
Executes a graph query.
It returns a Promise when a callback is not provided.
Gets the host that are replicas of a given token.
getState
()Gets a snapshot containing information on the connections pools held by this Client at the current time.
The information provided in the returned object only represents the state at the moment this method was called and it’s not maintained in sync with the driver metadata.
shutdown
([function callback])
Closes all connections to all hosts.
It returns a Promise when a callback is not provided.
Executes the query and pushes the rows to the result stream as soon as they received.
The stream is a ReadableStream object
that emits rows.
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.