ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Deployments
    • Cloud
    • Server
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
    • Supported Driver Versions
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Install
Search Ask AI
ScyllaDB Docs ScyllaDB Node.js Driver API Reference Classes Client
For AI agents: a documentation index is available at https://nodejs-rs-driver.docs.scylladb.com/main/llms.txt. A Markdown version of this page is at https://nodejs-rs-driver.docs.scylladb.com/main/api/Client.md.

Caution

You're viewing documentation for an unstable version of ScyllaDB Node.js Driver. Switch to the latest stable version.

Client¶

Client(options)

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.

Constructor¶

new Client(options)

Creates a new instance of Client.

Parameters:
Name Type Description
options

The options for this instance.

Source

client.ts, line 92

Examples

Creating a new client instance

const client = new Client({
  contactPoints: ['10.0.1.101', '10.0.1.102'],
});

Executing a query

const result = await client.connect();
console.log(`Connected to ${client.hosts.length} nodes in the cluster: ${client.hosts.keys().join(', ')}`);

Executing a query

const result = await client.execute('SELECT key FROM system.local');
const row = result.first();
console.log(row['key']);

Extends¶

  • events.EventEmitter

Members¶

hosts

Gets an associative array of cluster hosts.

Source

client.ts, line 205

keyspace

Gets the name of the active keyspace.

Source

client.ts, line 193

metadata

Gets the schema and cluster metadata information. TODO: This field is currently not supported

Source

client.ts, line 131

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. TODO: This field is currently not supported

Source

client.ts, line 139

Methods¶

batch(queries, options, callback)

Executes batch of queries on an available connection to a host.

It returns a Promise when a callback is not provided.

Parameters:
Name Type Description
queries

The queries to execute as an Array of strings or as an array of object containing the query and params.

options

The query options.

callback

Executes callback(err, result) when the batch was executed

Source

client.ts, line 814

connect(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.

Parameters:
Name Type Description
callback

The optional callback that is invoked when the pool is connected or it failed to connect.

Source

client.ts, line 262

Example

Usage example

await client.connect();

eachRow(query, params, options, rowCallback, 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.

Parameters:
Name Type Description
query

The query to execute

params

Array of parameter values or an associative array (object) containing parameter names as keys and its value.

options

The query options.

rowCallback

Executes rowCallback(n, row) per each row received, where n is the row index and row is the current Row.

callback

Executes callback(err, result) after all rows have been received.

When dealing with paged results, ResultSet#nextPage() method can be used to retrieve the following page. In that case, rowCallback() will be again called for each row and the final callback will be invoked when all rows in the following page has been retrieved.

Source

client.ts, line 646

Examples

Using per-row callback and arrow functions

client.eachRow(query, params, { prepare: true }, (n, row) => console.log(n, row), err => console.error(err));

Overloads

client.eachRow(query, rowCallback);
client.eachRow(query, params, rowCallback);
client.eachRow(query, params, options, rowCallback);
client.eachRow(query, params, rowCallback, callback);
client.eachRow(query, params, options, rowCallback, callback);

execute(query, params, options, callback)

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.

Parameters:
Name Type Description
query

The query to execute.

params

Array of parameter values or an associative array (object) containing parameter names as keys and its value.

options

The query options for the execution.

callback

Executes callback(err, result) when execution completed. When not defined, the method will return a promise.

See:
  • ExecutionProfile to reuse a set of options across different query executions.

Source

client.ts, line 385

Examples

Promise-based API, using async/await

const query = 'SELECT name, email FROM users WHERE id = ?';
const result = await client.execute(query, [ id ], { prepare: true });
const row = result.first();
console.log('%s: %s', row['name'], row['email']);

Callback-based API

const query = 'SELECT name, email FROM users WHERE id = ?';
client.execute(query, [ id ], { prepare: true }, function (err, result) {
  assert.ifError(err);
  const row = result.first();
  console.log('%s: %s', row['name'], row['email']);
});

executeGraph()

Source

client.ts, line 615

Deprecated

Not supported by the driver. Usage will throw an error.

getReplicas()

Gets the host that are replicas of a given token.

Source

client.ts, line 914

getState()

Source

client.ts, line 925

Deprecated

This is not planned feature for the driver. Currently this remains in place, but returns Client state with no information. This endpoint may be removed at any point.

Returns:

A dummy ClientState instance.

shutdown(callback)

The only effect of calling shutdown is rejecting any following queries to the database.

It returns a Promise when a callback is not provided.

Parameters:
Name Type Description
callback

Optional callback to be invoked when finished closing all connections.

Source

client.ts, line 941

Deprecated

Explicit connection shutdown is deprecated and may be removed in the future. Drop this client to close the connection to the database.

stream(query, params, options, callback)

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.

Parameters:
Name Type Description
query

The query to prepare and execute.

params

Array of parameter values or an associative array (object) containing parameter names as keys and its value

options

The query options.

callback

executes callback(err) after all rows have been received or if there is an error

Source

client.ts, line 750

Events¶

hostAdd

Emitted when a new host is added to the cluster.

  • Host The host being added.

Source

client.ts, line 169

hostDown

Emitted when a host in the cluster changed status from up to down.

  • host The host that changed the status.

Source

client.ts, line 184

hostRemove

Emitted when a host is removed from the cluster

  • Host The host being removed.

Source

client.ts, line 174

hostUp

Emitted when a host in the cluster changed status from down to up.

  • host The host that changed the status.

Source

client.ts, line 179

Was this page helpful?

PREVIOUS
ByteOrderedToken
NEXT
ColumnInfo
  • Create an issue
  • Edit this page

On this page

  • Client
    • Constructor
    • Extends
    • Members
    • Methods
    • Events
ScyllaDB Node.js Driver
Search Ask AI
  • main
    • main
    • v0.6.1
  • Getting Started
  • Statements
    • Executing CQL Statements - Best Practices
    • Unprepared Statements
    • Batch Statements
    • Parameterized queries
  • Fetching Large Result Sets
  • Logging
  • Policies
    • Load Balancing
    • Retry Policies
  • Authentication
  • Shutdown
  • Migration Guide
  • API Reference
    • Modules
      • auth
        • AuthProvider
        • Authenticator
        • PlainTextAuthProvider
      • concurrent
      • datastax
        • graph
        • search
      • errors
        • ArgumentError
        • AuthenticationError
        • BusyConnectionError
        • DriverInternalError
        • NoHostAvailableError
        • NotSupportedError
        • OperationTimedOutError
        • ResponseError
      • geometry
      • mapping
        • DefaultTableMappings
        • Mapper
        • ModelBatchItem
        • ModelMapper
        • Result
        • UnderscoreCqlToCamelCaseMappings
        • TableMappings
      • metadata
        • Aggregate
        • ClientState
        • ColumnMetadata
        • Index
        • KeyspaceMetadata
        • MaterializedView
        • Metadata
        • SchemaFunction
        • Strategy
        • TableMetadata
        • Udt
        • UdtField
      • metrics
        • DefaultMetrics
        • ClientMetrics
      • policies
        • addressResolution
          • AddressTranslator
          • EC2MultiRegionTranslator
          • MappingAddressTranslator
        • loadBalancing
          • AllowListPolicy
          • DCAwareRoundRobinPolicy
          • DefaultLoadBalancingPolicy
          • LegacyDefaultLoadBalancingPolicy
          • LoadBalancingConfig
          • LoadBalancingPolicy
          • RoundRobinPolicy
          • TokenAwarePolicy
        • reconnection
          • ConstantReconnectionPolicy
          • ExponentialReconnectionPolicy
          • ReconnectionPolicy
        • retry
          • FallthroughRetryPolicy
          • RetryPolicy
        • speculativeExecution
          • ConstantSpeculativeExecutionPolicy
          • NoSpeculativeExecutionPolicy
          • SpeculativeExecutionPolicy
        • timestampGeneration
          • MonotonicTimestampGenerator
          • TimestampGenerator
      • tracker
        • RequestLogger
        • RequestTracker
      • types
        • BigDecimal
        • Duration
        • InetAddress
        • Integer
        • LocalDate
        • Long
        • ResultSet
        • ResultStream
        • Row
        • TimeUuid
        • Tuple
        • Uuid
        • Vector
    • Classes
      • AddressResolver
      • ByteOrderedToken
      • Client
      • ColumnInfo
      • DateRange
      • DateRangeBound
      • DseGssapiAuthProvider
      • DsePlainTextAuthProvider
      • Edge
      • Element
      • Encoder
      • EncoderMembers
      • ExecutionOptions
      • ExecutionProfile
      • FrameReader
      • GraphResultSet
      • HashSet
      • LineString
      • Murmur3Token
      • Path
      • Point
      • Polygon
      • Property
      • RandomToken
      • SslOptions
      • Token
      • TokenRange
      • Vertex
      • VertexProperty
    • Interfaces
    • Events
    • Global Functions and Constants
Docs Tutorials University Contact Us About Us
© 2026 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 10 Aug 2026.
Powered by Sphinx 9.1.0 & ScyllaDB Theme 1.9.3