Overview

Represents an interface to some Data-API-enabled database instance. This is the entrypoint for database-level DML, such as creating/deleting collections/tables, connecting to collections/tables, and executing arbitrary commands.

Shouldn't be instantiated directly; use DataAPIClient.db to obtain an instance of this class.

Note that creating an instance of a Db doesn't trigger actual database creation; the database must have already existed beforehand. If you need to create a new database, use the AstraAdmin class.

Example

// Connect to a database using a direct endpoint
const db = client.db('*ENDPOINT*');

// Overrides default options from the DataAPIClient
const db = client.db('*ENDPOINT*', {
  keyspace: 'my_keyspace',
  useHttp2: false,
});
The "working keyspace"

The Db class has a concept of a "working keyspace", which is the default keyspace used for all operations in the database. This can be overridden in each method call, but if not, the default keyspace is used.

If no explicit keyspace is provided when creating the Db instance, it will default to:

  • On DataStax Astra dbs: default_keyspace
  • On all other dbs, it will remain undefined
    • In this case, the keyspace must be set using either:
      • The db.useKeyspace() mutator method
      • The updateDbKeyspace parameter in dbAdmin.createKeyspace()

Changing the working namespaces does NOT retroactively update any collections/tables spawned from this Db instance.

See Db.useKeyspace and DbAdmin.createKeyspace for more information.

Example

// Method 1:
db.useKeyspace('my_keyspace');

// Method 2:
// (If using non-astra, this may be a common idiom)
await db.admin().createKeyspace('my_keyspace', {
  updateDbKeyspace: true,
});
Astra vs. non-Astra

The Db class is designed to work with both Astra and non-Astra databases. However, there are some differences in behaviour between the two:

  • Astra DBs have an ID & region, which can be accessed using db.id and db.region respectively
  • Astra DBs have a db.info() method, which provides detailed information about the database
  • The db.admin() method will return differently depending on the environment
    • For Astra DBs, it will return an AstraDbAdmin instance
    • For non-Astra DBs, it will return a DataAPIDbAdmin instance
    • (The environment option must also be set in the admin() method)
  • As aforementioned, the default keyspace is different between Astra and non-Astra databases
    • See the previous section for more information

See

  • DataAPIClient.db
  • AstraAdmin.db
  • Table
  • Collection
  • DbAdmin

Constructors

Properties

#defaultOpts: InternalRootClientOpts
#endpoint: string
#httpClient: DataAPIHttpClient<"normal">
#id?: string
#keyspace: KeyspaceRef
#region?: string

Accessors

  • get _httpClient(): DataAPIHttpClient<"normal">
  • Returns DataAPIHttpClient<"normal">

  • get id(): string
  • The ID of the database (UUID), if it's an Astra database.

    If it's not an Astra database, this will throw an error, as they have no applicable/appropriate ID.

    Returns string

    Throws

    InvalidEnvironmentError - if the database is not an Astra database.

  • get keyspace(): string
  • The default keyspace to use for all operations in this database, unless overridden in a method call.

    Returns string

    Example

    // Uses 'default_keyspace' as the default keyspace for all future db spawns
    const client1 = new DataAPIClient('*TOKEN*');

    // Overrides the default keyspace for all future db spawns
    const client2 = new DataAPIClient('*TOKEN*', {
      dbOptions: { keyspace: 'my_keyspace' },
    });

    // Created with 'default_keyspace' as the default keyspace
    const db1 = client1.db('*ENDPOINT*');

    // Created with 'my_keyspace' as the default keyspace
    const db2 = client1.db('*ENDPOINT*', {
      keyspace: 'my_keyspace'
    });

    // Uses 'default_keyspace'
    const coll1 = db1.collection('users');

    // Uses 'my_keyspace'
    const coll2 = db1.collection('users', {
      keyspace: 'my_keyspace'
    });
  • get region(): string
  • The region of the database (e.g. 'us-east-1'), if it's an Astra database.

    If it's not an Astra database, this will throw an error, as they have no applicable/appropriate region.

    Returns string

    Throws

    InvalidEnvironmentError - if the database is not an Astra database.

Methods

  • Overview

    Spawns a new AstraDbAdmin instance for this database, used for performing administrative operations on the database, such as managing keyspaces, or getting database information.

    The given options will override any default options set when creating the DataAPIClient through a deep merge (i.e. unset properties in the options object will just default to the default options).

    Parameters

    • Optional options: AdminOptions & {
          environment?: "astra";
      }

      Any options to override the default options set when creating the DataAPIClient.

    Returns AstraDbAdmin

    A new AstraDbAdmin instance for this database instance.

    Example

    const admin1 = db.admin();
    const admin2 = db.admin({ adminToken: '<stronger-token>' });

    const keyspaces = await admin1.listKeyspaces();
    console.log(keyspaces);
    Astra vs. non-Astra

    If using a non-Astra backend, the environment option MUST be set as it is on the DataAPIClient

    If on Astra, this method will return a new AstraDbAdmin instance, which provides a few extra methods for Astra databases, such as AstraDbAdmin.info or AstraDbAdmin.drop.

    Throws

    InvalidEnvironmentError - if the database is not an Astra database.

  • Overview

    Spawns a new DataAPIDbAdmin instance for this database, used for performing administrative operations on the database, such as managing keyspaces, or getting database information.

    The given options will override any default options set when creating the DataAPIClient through a deep merge (i.e. unset properties in the options object will just default to the default options).

    If using a non-Astra backend, the environment option MUST be set as it is on the DataAPIClient

    Parameters

    • options: AdminOptions & {
          environment: "dse" | "hcd" | "cassandra" | "other";
      }

      Any options to override the default options set when creating the DataAPIClient.

    Returns DataAPIDbAdmin

    A new AstraDbAdmin instance for this database instance.

    Example

    const client = new DataAPIClient({ environment: 'dse' });
    const db = client.db('*ENDPOINT*', { token });

    // OK
    const admin1 = db.admin({ environment: 'dse' });

    // Will throw "mismatching environments" error
    const admin2 = db.admin();

    const keyspaces = await admin1.listKeyspaces();
    console.log(keyspaces);
    Astra vs. non-Astra

    If using a non-Astra backend, the environment option MUST be set as it is on the DataAPIClient

    If on non-Astra, this method will return a new DataAPIDbAdmin instance, which conforms strictly to the DbAdmin interface, with the DataAPIDbAdmin.createKeyspace method being the only method that differs slightly from the interface version.

    Throws

    InvalidEnvironmentError - if the database is not an Astra database.

  • Overview

    Establishes a reference to a collection in the database. This method does not perform any I/O.

    NOTE: This method does not validate the existence of the collection—it simply creates a reference.

    Type Parameters

    Parameters

    • name: string

      The name of the collection.

    • Optional options: CollectionOptions

      Options for spawning the collection.

    Returns Collection<WSchema, RSchema>

    A new, unvalidated, reference to the collection.

    Example

    interface User {
      name: string,
      age?: number,
    }

    // Basic usage
    const users1 = db.collection<User>('users');
    users1.insertOne({ name: 'John' });

    // Untyped collection from different keyspace
    const users2 = db.collection('users', {
      keyspace: 'my_keyspace',
    });
    users2.insertOne({ 'anything[you]$want': 'John' }); // Dangerous
    No I/O

    Unlike the MongoDB Node.js driver, this method does not create a collection if it doesn't exist.

    Use Db.createCollection to create a new collection instead.

    Typing & Types

    Collections are inherently untyped, but you can provide your own client-side compile-time schema for type inference and early-bug-catching purposes.

    A Collection is typed as Collection<Schema extends SomeDoc = SomeDoc>, where:

    • Schema is the user-intended type of the documents in the collection.
    • SomeDoc is set to Record<string, any>, representing any valid JSON object.

    Certain datatypes may be represented as TypeScript classes (some native, some provided by astra-db-ts), however.

    You may also provide your own datatypes by providing some custom serialization logic as well (see later section).

    Please see Collection for much more info on typing them, and more.

    Example

    import { UUID, DataAPIVector, ... } from 'astra-db-ts';

    interface User {
      _id: string,
      dob: Date,
      friends?: Record<string, UUID>, // UUID is also `astra-db-ts` provided
      vector: DataAPIVector,
    }

    const collection = db.collection<User>('users');

    // res.insertedId is of type string
    const res = await collection.insertOne({
      _id: '123',
      dob: new Date(),
      friends: { 'Alice': UUID.random() },
      vector: new DataAPIVector([1, 2, 3]), // This can also be passed as a number[]
    });
    Disclaimer

    Collections are inherently untyped

    It is on the user to ensure that the TS type of the Collection corresponds with the actual CQL table schema, in its TS-deserialized form. Incorrect or dynamic tying could lead to surprising behaviours and easily-preventable errors.

    There is no runtime type validation or enforcement of the schema.

    See

    • SomeDoc
    • VectorDoc
    • VectorizeDoc
    • db.createCollection
  • Send a POST request to the Data API for this database with an arbitrary, caller-provided payload.

    You can specify a table/collection to target in the options parameter, thereby allowing you to perform arbitrary table/collection-level operations as well.

    If the keyspace is set to null, the command will be run at the database level.

    If no collection is specified, the command will be executed at the keyspace level.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    • command: Record<string, any>

      The command to send to the Data API.

    • Optional options: RunCommandOptions

      Options for this operation.

    Returns Promise<RawDataAPIResponse>

    A promise that resolves to the raw response from the Data API.

    Example

    const colls = await db.command({ findCollections: {} });
    console.log(colls); // { status: { collections: [] } }

    const user = await db.command({ findOne: {} }, { collection: 'users' });
    console.log(user); // { data: { document: null } }

    const post = await db.command({ findOne: {} }, { table: 'posts' });
    console.log(post); // { data: { document: null } }
  • Overview

    Creates a new collection in the database, and establishes a reference to it.

    This is a blocking command which performs actual I/O (unlike Db.collection, which simply creates an unvalidated reference to a collection).

    Type Parameters

    Parameters

    Returns Promise<Collection<WSchema, RSchema>>

    A promised reference to the newly created collection.

    Example

    // Most basic usage
    const users = await db.createCollection('users');

    // With custom options in a different keyspace
    const users2 = await db.createCollection('users', {
      keyspace: 'my_keyspace',
      defaultId: {
      type: 'objectId',
      },
    });
    Idempotency

    Creating a collection is idempotent as long as the options remain the same; if the collection already exists with the same options, a DataAPIResponseError will be thrown.

    ("options" mean the createCollection options actually sent to the server, not things like timeout which are just client-side).

    Enabling vector search

    If vector options are not specified, the collection will not support vector search.

    You can enable it by providing a vector option with the desired configuration, optionally with a vector.service block to enable vectorize (auto-embedding-generation).

    Example

    const users = await db.createCollection('users', {
      vector: {
      service: {
      provider: 'nvidia',
      modelName: 'NV-Embed-QA',
      },
      },
    });

    // Now, `users` supports vector search
    await users.insertOne({ $vectorize: 'I like cars!!!' });
    await users.fineOne({}, { sort: { $vectorize: 'I like cars!!!' } });
    Typing & Types

    Collections are inherently untyped, but you can provide your own client-side compile-time schema for type inference and early-bug-catching purposes.

    A Collection is typed as Collection<Schema extends SomeDoc = SomeDoc>, where:

    • Schema is the user-intended type of the documents in the collection.
    • SomeDoc is set to Record<string, any>, representing any valid JSON object.

    Certain datatypes may be represented as TypeScript classes (some native, some provided by astra-db-ts), however.

    You may also provide your own datatypes by providing some custom serialization logic as well (see later section).

    Please see Collection for much more info on typing them, and more.

    Example

    import { UUID, DataAPIVector, ... } from 'astra-db-ts';

    interface User {
      _id: string,
      dob: Date,
      friends?: Record<string, UUID>, // UUID is also `astra-db-ts` provided
      vector: DataAPIVector,
    }

    const collection = await db.createCollection<User>('users');

    // res.insertedId is of type string
    const res = await collection.insertOne({
      _id: '123',
      dob: new Date(),
      friends: { 'Alice': UUID.random() },
      vector: new DataAPIVector([1, 2, 3]), // This can also be passed as a number[]
    });
    Disclaimer

    Collections are inherently untyped

    It is on the user to ensure that the TS type of the Collection corresponds with the actual CQL table schema, in its TS-deserialized form. Incorrect or dynamic tying could lead to surprising behaviours and easily-preventable errors.

    There is no runtime type validation or enforcement of the schema.

    Throws

    CollectionAlreadyExistsError - if the collection already exists and checkExists is true or unset.

    See

    • SomeDoc
    • db.collection
  • Overview

    Creates a new table in the database, and establishes a reference to it.

    This is a blocking command which performs actual I/O (unlike Db.table, which simply creates an unvalidated reference to a table).

    Overloads

    This overload of createTable infers the TS-equivalent schema of the table from the provided CreateTableDefinition.

    Provide an explicit Schema type to disable this (e.g. db.createTable<SomeRow>(...)).

    Type Parameters

    Parameters

    Returns Promise<Table<InferTableSchema<Def>, InferTablePrimaryKey<Def>, FoundRow<InferTableSchema<Def>>>>

    A promised reference to the newly created table.

    Example

    // Function to create the actual table
    const mkUserTable = () => db.createTable('users', {
      definition: {
      columns: {
      name: 'text',
      dob: {
      type: 'timestamp',
      },
      friends: {
      type: 'set',
      valueType: 'text',
      },
      },
      primaryKey: {
      partitionBy: ['name', 'height'],
      partitionSort: { dob: 1 },
      },
      },
    });

    // Type inference is as simple as that
    type User = InferTableSchema<typeof mkUserTable>;

    // And now `User` can be used wherever.
    const main = async () => {
      const table = await mkUserTable();
      const found: User | null = await table.findOne({});
    };
    Idempotency

    Creating a table is idempotent if the ifNotExists option is set to true. Otherwise, an error will be thrown if a table with the same name is thrown.

    If a table is "recreated" with the same name & ifNotExists is set to true, but the columns definition differ, the operation will silently succeed, but the original table schema will be retained.

    Typing & Types

    A Table is typed as Table<Schema extends SomeRow = SomeRow>, where:

    • Schema is the type of the rows in the table (the table schema).
    • SomeRow is set to Record<string, any>, representing any valid JSON object.

    Certain datatypes may be represented as TypeScript classes (some native, some provided by astra-db-ts), however.

    You may also provide your own datatypes by providing some custom serialization logic as well (see later section).

    Please see Table for much more info on typing them, and more.

    Disclaimer

    It is on the user to ensure that the TS type of the Table corresponds with the actual CQL table schema, in its TS-deserialized form. Incorrect or dynamic tying could lead to surprising behaviours and easily-preventable errors.

    See Db.createTable, Db.table, and InferTableSchema for much more information about typing.

    See

    • SomeRow
    • db.table
    • InferTableSchema
    • InferTablePrimaryKey
    • CreateTableDefinition
  • Overview

    Creates a new table in the database, and establishes a reference to it.

    This is a blocking command which performs actual I/O (unlike Db.table, which simply creates an unvalidated reference to a table).

    Overloads

    This overload of createTable uses the provided Schema type to type the Table.

    Don't provide a Schema type if you want to infer it from the CreateTableDefinition via InferTableSchema.

    Type Parameters

    Parameters

    Returns Promise<Table<WSchema, PKeys, RSchema>>

    A promised reference to the newly created table.

    Example

    interface User {
      name: string,
      dob: DataAPIDate,
      friends?: Set<string>,
    }

    type UserPK = Pick<User, 'name' | 'dob'>;

    const table = await db.createTable<User, UserPK>('users', {
    definition: {
    columns: {
    name: 'text',
    dob: {
    type: 'timestamp',
    },
    friends: {
    type: 'set',
    valueType: 'text',
    },
    },
    primaryKey: {
    partitionBy: ['name'],
    partitionSort: { dob: 1 },
    },
    },
    });

    const found: User | null = await table.findOne({});
    Idempotency

    Creating a table is idempotent if the ifNotExists option is set to true. Otherwise, an error will be thrown if a table with the same name is thrown.

    If a table is "recreated" with the same name & ifNotExists is set to true, but the columns definition differ, the operation will silently succeed, but the original table schema will be retained.

    Typing & Types

    A Table is typed as Table<Schema extends SomeRow = SomeRow>, where:

    • Schema is the type of the rows in the table (the table schema).
    • SomeRow is set to Record<string, any>, representing any valid JSON object.

    Certain datatypes may be represented as TypeScript classes (some native, some provided by astra-db-ts), however.

    You may also provide your own datatypes by providing some custom serialization logic as well (see later section).

    Please see Table for much more info on typing them, and more.

    Disclaimer

    It is on the user to ensure that the TS type of the Table corresponds with the actual CQL table schema, in its TS-deserialized form. Incorrect or dynamic tying could lead to surprising behaviours and easily-preventable errors.

    See Db.createTable, Db.table, and InferTableSchema for much more information about typing.

    See

    • SomeRow
    • db.table
    • InferTableSchema
    • InferTablePrimaryKey
    • CreateTableDefinition
  • Overview

    Drops a collection from the database, including all the contained documents.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    • name: string

      The name of the collection to drop.

    • Optional options: DropCollectionOptions

      Options for this operation.

    Returns Promise<void>

    A promise that resolves to true if the collection was dropped successfully.

    Example

    // Uses db's working keyspace
    const success1 = await db.dropCollection('users');
    console.log(success1); // true

    // Overrides db's working keyspace
    const success2 = await db.dropCollection('users', {
      keyspace: 'my_keyspace'
    });
    console.log(success2); // true

    Remarks

    Use with caution. Have steel-toe boots on. Don't say I didn't warn you.

  • Overview

    Drops a table from the database, including all the contained rows.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    • name: string

      The name of the table to drop.

    • Optional options: DropTableOptions

      Options for this operation.

    Returns Promise<void>

    A promise that resolves to true if the table was dropped successfully.

    Example

    // Uses db's working keyspace
    const success1 = await db.dropTable('users');
    console.log(success1); // true

    // Overrides db's working keyspace
    const success2 = await db.dropTable('users', {
      keyspace: 'my_keyspace'
    });
    console.log(success2); // true

    Remarks

    Use with caution. Wear a mask. Don't say I didn't warn you.

  • Overview

    Drops an index from the database.

    This operation is idempotent if ifExists is set to true.

    See Table.createIndex & Table.createVectorIndex

    Name uniqueness

    The name of the index is must actually be unique per keyspace, which is why this is a database-level command: to make it clear that the index is being dropped from the keyspace, not a specific table.

    Parameters

    • name: string

      The name of the index to drop.

    • Optional options: TableDropIndexOptions

      The options for this operation.

    Returns Promise<void>

    A promise that resolves when the index is dropped.

  • Overview

    Fetches information about the database, such as the database name, region, and other metadata.

    NOTE: Only available for Astra databases.

    For the full, complete, information, see AstraDbAdmin.info.

    The method issues a request to the DevOps API each time it is invoked, without caching mechanisms; this ensures up-to-date information for usages such as real-time collection validation by the application.

    Parameters

    • Optional options: WithTimeout<"databaseAdminTimeoutMs">

    Returns Promise<AstraDbInfo>

    A promise that resolves to the database information.

    Example

    const info = await db.info();
    console.log(info.name);
    On non-Astra

    This operation requires a call to the DevOps API, which is only available on Astra databases. As such, this method will throw an error if the database is not an Astra database.

    Throws

    Error - if the database is not an Astra database.

  • Lists the collection names in the database.

    If you want to include the collection options in the response, set nameOnly to false (or omit it completely), using the other overload.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    Returns Promise<string[]>

    A promise that resolves to an array of collection names.

    Example

    // ['users', 'posts']
    console.log(await db.listCollections({ nameOnly: true }));
  • Lists the collections in the database.

    If you want to use only the collection names, set nameOnly to true, using the other overload.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    Returns Promise<CollectionDescriptor[]>

    A promise that resolves to an array of collection info.

    Example

    // [{ name: 'users' }, { name: 'posts', options: { ... } }]
    console.log(await db.listCollections());
  • Lists the table names in the database.

    If you want to include the table options in the response, set nameOnly to false (or omit it completely), using the other overload.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    Returns Promise<string[]>

    A promise that resolves to an array of table names.

    Example

    // ['users', 'posts']
    console.log(await db.listTables({ nameOnly: true }));
  • Lists the tables in the database.

    If you want to use only the table names, set nameOnly to true, using the other overload.

    You can also specify a keyspace in the options parameter, which will override the working keyspace for this Db instance.

    Parameters

    • Optional options: ListTablesOptions & {
          nameOnly?: false;
      }

      Options for this operation.

    Returns Promise<TableDescriptor[]>

    A promise that resolves to an array of table info.

    Example

    // [{ name: 'users' }, { name: 'posts', definition: { ... } }]
    console.log(await db.listTables());
  • Overview

    Establishes a reference to a table in the database. This method does not perform any I/O.

    NOTE: This method does not validate the existence of the table—it simply creates a reference.

    Type Parameters

    Parameters

    • name: string

      The name of the table.

    • Optional options: TableOptions

      Options for spawning the table.

    Returns Table<WSchema, PKeys, RSchema>

    A new, unvalidated, reference to the table.

    Example

    interface User {
      name: string,
      age?: number,
    }

    // Basic usage
    const users1 = db.table<User>('users');
    users1.insertOne({ name: 'John' });

    // Untyped table from different keyspace
    const users2 = db.table('users', {
      keyspace: 'my_keyspace',
    });
    users2.insertOne({ 'anything[you]$want': 'John' }); // Dangerous
    No I/O

    This method does not create a table if it doesn't exist.

    Use Db.createTable to create a new table instead.

    Typing & Types

    A Table is typed as Table<Schema extends SomeRow = SomeRow>, where:

    • Schema is the type of the rows in the table (the table schema).
    • SomeRow is set to Record<string, any>, representing any valid JSON object.

    Certain datatypes may be represented as TypeScript classes (some native, some provided by astra-db-ts), however.

    You may also provide your own datatypes by providing some custom serialization logic as well (see later section).

    Please see Table for much more info on typing them, and more.

    Example

    import { DataAPIDate, UUID, DataAPIVector, ... } from 'astra-db-ts';

    interface User {
      id: string, // Partition key
      dob: DataAPIDate, // Clustering (partition sort) key
      friends: Map<string, UUID>,
      vector: DataAPIVector,
    }

    type UserPK = Pick<User, 'id' | 'dob'>;

    const table = db.table<User, UserPK>('users');

    // res.insertedId is of type { id: string }
    const res = await table.insertOne({
      id: '123',
      dob: new DataAPIDate(new Date()),
      friends: new Map([['Alice', UUID.random()]]),
      vector: new DataAPIVector([1, 2, 3]), // Class enables encoding optimization
    });
    Disclaimer

    It is on the user to ensure that the TS type of the Table corresponds with the actual CQL table schema, in its TS-deserialized form. Incorrect or dynamic tying could lead to surprising behaviours and easily-preventable errors.

    See Db.createTable, Db.table, and InferTableSchema for much more information about typing.

    See

    • SomeRow
    • db.createTable
    • InferTableSchema
    • InferTablePrimaryKey
  • Overview

    Sets the default working keyspace of the Db instance. Does not retroactively update any previous collections spawned from this Db to use the new keyspace.

    See Db for more info on "working keyspaces".

    Parameters

    • keyspace: string

      The keyspace to use

    Returns void

    Example

    // Spawns a `Db` with default working keyspace `my_keyspace`
    const db = client.db('<endpoint>', { keyspace: 'my_keyspace' });

    // Gets a collection from keyspace `my_keyspace`
    const coll1 = db.collection('my_coll');

    // `db` now uses `my_other_keyspace` as the default keyspace for all operations
    db.useKeyspace('my_other_keyspace');

    // Gets a collection from keyspace `my_other_keyspace`
    // `coll1` still uses keyspace `my_keyspace`
    const coll2 = db.collection('my_other_coll');

    // Gets `my_coll` from keyspace `my_keyspace` again
    // (The default keyspace is still `my_other_keyspace`)
    const coll3 = db.collection('my_coll', { keyspace: 'my_keyspace' });
    updateDbKeyspace in DbAdmin.createKeyspace

    If you want to create a Db in a not-yet-existing keyspace, you can use the updateDbKeyspace option in DbAdmin.createKeyspace to set the default keyspace of the Db instance to the new keyspace.

    This may be a common idiom when working with non-Astra databases.

    Example

    const client = new DataAPIClient({ environment: 'dse' });
    const db = client.db('<endpoint>', { token: '<token>' });

    // Will internally call `db.useKeyspace('new_keyspace')`
    await db.admin().createKeyspace('new_keyspace', {
      updateDbKeyspace: true,
    });

    // Creates collection in keyspace `new_keyspace` by default now
    const coll = db.createCollection('my_coll');