Get a database object (TypeScript)

When using a client, most Data API interactions require you to connect to a database through a DataAPIClient object.

Connecting to a database is an essential component of most Data API client scripts. For more information, see Get started with the Data API (TypeScript).

For more information about the Data API client hierarchy, see Python client internals, TypeScript client internals, Go client internals, Java client internals, and C# client internals.

Result

Returns a Db object that you can use to perform CRUD operations on your database

Parameters

Use the db method, which belongs to the DataAPIClient class.

Method signature
db(
  endpoint: string,
  options?: {
    logging?: LoggingConfig,
    keyspace?: string | null,
    token?: string | TokenProvider | null,
    dataApiPath?: string,
    serdes?: DbSerDesConfig,
    timeoutDefaults?: TimeoutDescriptor,
  }
): Db
Name Type Summary

endpoint

string

A database API endpoint URL, such as https://DATABASE_ID-REGION.apps.astra.datastax.com.

options

RootDbOptions

Optional. The options to use for the database. See Properties of options for more details.

Properties of options
Name Type Summary

keyspace

string

Optional. Specify the working keyspace. This keyspace is used for all downstream operations unless you later override it with a method such as useKeyspace, collection, createCollection, table, or createTable.

Default: default_keyspace

monitorCommands

boolean

Optional. Whether to monitor commands through CommandEvents, using the client as an event emitter.

Default: false.

token

string

Optional. An application token for a database. Tokens are prefixed with AstraCS:.

The token should have sufficient permissions to perform the desired operations.

If you specified a token when instantiating the DataAPIClient, that token will be overridden.

dataApiPath

string

Optional. The path to the Data API.

Default: 'api/json/v1'.

Examples

The following examples demonstrate how to connect to a database.

import { DataAPIClient } from "@datastax/astra-db-ts";

const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
  token: "APPLICATION_TOKEN",
});

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM