Optional
additionalAdditional headers to include in the HTTP requests to the DevOps API.
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.
Optional
dataThe 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.
'api/json/v1'
Optional
keyspaceThe keyspace to use for the database.
There are a few rules for what the default keyspace will be:
astra
database, it'll default to "default_keyspace".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.
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_keyspace'
Optional
loggingThe 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.
Optional
Beta
serdesAdvanced & 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.
Optional
timeoutThe default timeout options for anything spawned by this Db instance.
See TimeoutDescriptor for much more information about timeouts.
// 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 },
});
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.
The default timeout options are as follows:
requestTimeoutMs
: 10000generalMethodTimeoutMs
: 30000collectionAdminTimeoutMs
: 60000tableAdminTimeoutMs
: 30000databaseAdminTimeoutMs
: 600000keyspaceAdminTimeoutMs
: 30000TimeoutDescriptor
Optional
tokenThe 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.
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',
});
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.