Get a table (TypeScript)

Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Hyper-Converged Database (HCD), and the use of such, is subject to the DataStax Preview Terms.

Gets a reference to a table for use with the Data API clients.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Returns a Table<Schema> object that corresponds to the specified table name.

This method returns a Table object even for tables that don’t exist.

Unless you specify the Schema, the table is typed as Table<Record<string, any>>.

Parameters

Use the table method, which belongs to the Db class.

Method signature
table(
  name: string,
  options?: {
    logging?: DataAPILoggingConfig,
    serdes?: TableSerDesConfig,
    timeoutDefaults?: Partial<TimeoutDescriptor>,
    keyspace?: string,
  },
): Table<Schema, PKeys>
Name Type Summary

name

string

The name of the table.

options

TableOptions

The options for this operation. See Properties of options for more details.

Properties of options
Name Type Summary

keyspace

string

Optional if you specified a working keyspace when you created the Db object. The keyspace containing the table.

Default: The working keyspace set when you created the Db object, if one was provided.

logging

DataAPILoggingConfig

Optional. The configuration for logging events emitted by the DataAPIClient. For more information, see Logging.

timeoutDefaults

Partial<TimeoutDescriptor>

Optional. The default timeout options for any operation performed on this Table instance. For more information, see TypeScript client internals: TimeoutDescriptor.

serdes

TableSerDesConfig

Optional. Lower-level serialization/deserialization configuration for this table. For more information, see Custom Ser/Des.

Examples

The following examples demonstrate how to get a table.

Get a table

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

// Get an existing table
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
  token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
  keyspace: "KEYSPACE_NAME",
});
const table = database.table("TABLE_NAME");

Get a table and specify typing

When you get a table, you can specify the table schema type.

If you specify the table schema type, you can also specify the primary key type. The primary key type is only used in the return types of the insertOne and insertMany methods. You don’t need to specify the primary key type if you don’t need to use the returned values from the insertOne and insertMany methods.

If you don’t specify any typing, the table rows are typed as Record<string, any>. This is the most flexible but least type-safe option.

For more information, see Collection and table typing.

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

// Manually define the type of the table's schema and primary key
type TableSchema = {
  title: string;
  author: string;
  number_of_pages?: number | null | undefined;
  rating?: number | null | undefined;
  genres?: Set<string> | undefined;
  metadata?: Map<string, string> | undefined;
  is_checked_out?: boolean | null | undefined;
  due_date?: DataAPIDate | null | undefined;
};

type TablePrimaryKey = Pick<TableSchema, "title" | "author">;

// Get an existing table
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
  token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
  keyspace: "KEYSPACE_NAME",
});
const table = database.table<TableSchema, TablePrimaryKey>("TABLE_NAME");

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