Get a database admin (TypeScript)
The Data API clients use the Database Admin class to perform administrative operations, like managing keyspaces, within a specific database.
To perform administrative actions outside of a specific database, see Get an Astra DB admin (TypeScript) instead.
The Database Admin class name varies by client.
The TypeScript client uses AstraDbAdmin.
|
You need an application token with permission to interact with the target database, such as the Database Administrator role. For more information, see Get endpoint and token. |
Result
Returns an AstraDbAdmin object that can perform administrative actions on the specified database.
Parameters
Use the admin method, which belongs to the Db class.
Method signature
admin(
options?: AdminOptions & {
environment?: "astra"
}
): AstraDbAdmin
| Name | Type | Summary |
|---|---|---|
|
|
Optional.
Only for the The database’s environment.
Must be |
|
Optional. A specification of options to override the inherited defaults. Use this to customize the interaction of the client with the database admin. For example, you can change the default timeouts or token. |
Alternatively, use the dbAdmin method, which belongs to the AstraDbAdmin class.
Alternative method signature and parameters
dbAdmin(
endpoint: string,
options?: DbOptions
): AstraDbAdmin
dbAdmin(
id: string,
region: string,,
options?: DbOptions
): AstraDbAdmin
| Name | Type | Summary |
|---|---|---|
|
|
The database’s API endpoint, typically formatted as |
|
|
The database’s ID. |
|
|
The database’s region. |
|
Optional. A specification of options to override the inherited defaults. Use this to customize the interaction of the client with the database admin. For example, you can change the default timeouts or token. |
Examples
The following examples demonstrate how to get a database admin object.
Get a database admin from a database
import { DataAPIClient } from "@datastax/astra-db-ts";
// Get a database object
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
token: "APPLICATION_TOKEN",
});
// Get a database admin object
const databaseAdmin = database.admin();
Get a database admin from an admin
import { DataAPIClient } from "@datastax/astra-db-ts";
// Get an admin object
const client = new DataAPIClient("APPLICATION_TOKEN");
const admin = client.admin();
// Get a database admin object
const databaseAdmin = admin.dbAdmin("API_ENDPOINT");
Client reference
For more information, see the client reference.