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

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.js, line 60

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¶

(package) connected

Source

client.js, line 71

(package) connecting

Source

client.js, line 73

hosts

Gets an associative array of cluster hosts.

Source

client.js, line 143

(package) isShuttingDown

Source

client.js, line 75

keyspace

Gets the name of the active keyspace.

Source

client.js, line 132

metadata

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

Source

client.js, line 80

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.js, line 88

(package) options

Source

client.js, line 66

(package) rustClient

Source

client.js, line 62

(package) rustOptions

Source

client.js, line 68

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.js, line 571

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.js, line 194

Example

Usage example

await client.connect();

(package) createOptions()

Manually create final execution options, applying client and default setting.

Creating those options requires a native call, but they can be reused without any additional native calls, which improves performance for queries with the same QueryOptions.

Source

client.js, line 162

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.js, line 448

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.js, line 281

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.js, line 418

Deprecated

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

getReplicas()

Gets the host that are replicas of a given token.

Source

client.js, line 644

getState()

Source

client.js, line 654

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.

(async, package) prepareStatement()

Manually prepare query into prepared statement.

Source

client.js, line 175

(async, package) rustyExecute(pageState)

Wrapper for executing queries by rust driver. When called with a pageState argument (including null), executes a single-page query. When called without pageState, executes an unpaged query.

Parameters:
Name Type Description
pageState

When provided (including null), enables paged execution. When unprovided (undefined), executes an unpaged query.

Source

client.js, line 323

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.js, line 668

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.js, line 518

Events¶

hostAdd

Emitted when a new host is added to the cluster.

  • Host The host being added.

Source

client.js, line 109

hostDown

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

  • host The host that changed the status.

Source

client.js, line 124

hostRemove

Emitted when a host is removed from the cluster

  • Host The host being removed.

Source

client.js, line 114

hostUp

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

  • host The host that changed the status.

Source

client.js, line 119

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
        • UdtField
        • UserDefinedType
      • 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
      • Host
      • HostMap
      • 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 20 Jun 2026.
Powered by Sphinx 9.1.0 & ScyllaDB Theme 1.9.2