The options available spawning a new Db instance.

If any of these options are not provided, the client will use the default options provided by the DataAPIClient.

interface DbOptions {
    additionalHeaders?: Record<string, string>;
    dataApiPath?: string;
    keyspace?: null | string;
    logging?: DataAPILoggingConfig;
    serdes?: DbSerDesConfig;
    timeoutDefaults?: Partial<TimeoutDescriptor>;
    token?: null | string | TokenProvider;
}

Properties

additionalHeaders?: Record<string, string>

Additional headers to include in the HTTP requests to the DevOps API.

Remarks

There are more than likely more official/structured ways to set any desired headers, such as through TokenProviders or EmbeddingHeadersProviders. This is more of a last-resort option, such as for enabling feature-flags or other non-standard headers.

dataApiPath?: string

The path to the Data API, which is going to be api/json/v1 for all Astra instances. However, it may vary if you're using a different Data API-compatible endpoint.

Defaults to 'api/json/v1' if never provided. However, if it was provided when creating the DataAPIClient, it will default to that value instead.

Default Value

'api/json/v1'
keyspace?: null | string

The keyspace to use for the database.

There are a few rules for what the default keyspace will be:

  1. If a keyspace was provided when creating the DataAPIClient, it will default to that value.
  2. If using an astra database, it'll default to "default_keyspace".
  3. Otherwise, no default will be set, and it'll be on the user to provide one when necessary.

The client itself will not throw an error if an invalid keyspace (or even no keyspace at all) is provided—it'll let the Data API propagate the error itself.

Every db method will use this keyspace as the default keyspace, but they all allow you to override it in their options.

Example

const client = new DataAPIClient('AstraCS:...');

// Using 'default_keyspace' as the keyspace
const db1 = client.db('https://<db_id>-<region>.apps.astra.datastax.com');

// Using 'my_keyspace' as the keyspace
const db2 = client.db('https://<db_id>-<region>.apps.astra.datastax.com', {
  keyspace: 'my_keyspace',
});

// Finds 'my_collection' in 'default_keyspace'
const coll1 = db1.collections('my_collection');

// Finds 'my_collection' in 'my_keyspace'
const coll2 = db1.collections('my_collection');

// Finds 'my_collection' in 'other_keyspace'
const coll3 = db1.collections('my_collection', { keyspace: 'other_keyspace' });

Default Value

'default_keyspace'

The configuration for logging events emitted by the DataAPIClient.

This can be set at any level of the major class hierarchy, and will be inherited by all child classes.

See DataAPILoggingConfig for much more information on configuration, outputs, and inheritance.

Advanced & currently somewhat unstable features related to customizing the client's ser/des behavior at a lower level.

Use with caution. See official DataStax documentation for more info.

timeoutDefaults?: Partial<TimeoutDescriptor>
Overview

The default timeout options for anything spawned by this Db instance.

See TimeoutDescriptor for much more information about timeouts.

Example

// The request timeout for all operations is set to 1000ms.
const client = new DataAPIClient('...', {
  timeoutDefaults: { requestTimeoutMs: 1000 },
});

// The request timeout for all operations borne from this Db is set to 2000ms.
const db = client.db('...', {
  timeoutDefaults: { requestTimeoutMs: 2000 },
});
Inheritance

The timeout options are inherited by all child classes, and can be overridden at any level, including the individual method level.

Individual-method-level overrides can vary in behavior depending on the method; again, see TimeoutDescriptor.

Defaults

The default timeout options are as follows:

  • requestTimeoutMs: 10000
  • generalMethodTimeoutMs: 30000
  • collectionAdminTimeoutMs: 60000
  • tableAdminTimeoutMs: 30000
  • databaseAdminTimeoutMs: 600000
  • keyspaceAdminTimeoutMs: 30000

See

TimeoutDescriptor

token?: null | string | TokenProvider

The access token for the Data API, typically of the format 'AstraCS:...'.

If never provided, this will default to the token provided when creating the DataAPIClient.

Example

const client = new DataAPIClient('strong-token');

// Using 'strong-token' as the token
const db1 = client.db('https://<db_id>-<region>.apps.astra.datastax.com');

// Using 'weaker-token' instead of 'strong-token'
const db2 = client.db('https://<db_id>-<region>.apps.astra.datastax.com', {
  token: 'weaker-token',
});