Share via


Database class

Operations for reading or deleting an existing database.

See Databases for creating new databases, and reading/querying all databases; use client.databases.

Note: all these operations make calls against a fixed budget. You should design your system such that these calls scale sublinearly with your application. For instance, do not call database.read() before every single item.read() call, to ensure the database exists; do this once on application start up.

Properties

client
containers

Used for creating new containers, or querying/reading all containers.

Use .database(id) to read, replace, or delete a specific, existing Database by id.

Example

Create a new container

const {body: containerDefinition, container} = await client.database("<db id>").containers.create({id: "<container id>"});
id
url

Returns a reference URL to the resource. Used for linking in Permissions.

users

Used for creating new users, or querying/reading all users.

Use .user(id) to read, replace, or delete a specific, existing User by id.

Methods

container(string)

Used to read, replace, or delete a specific, existing Database by id.

Use .containers creating new containers, or querying/reading all containers.

Example

Delete a container

await client.database("<db id>").container("<container id>").delete();
createClientEncryptionKey(string, AEAD_AES_256_CBC_HMAC_SHA256, EncryptionKeyWrapMetadata)

Create Encryption key for database account

delete(RequestOptions)

Delete the given Database.

read(RequestOptions)

Read the definition of the given Database.

readClientEncryptionKey(string)

Read Encryption key for database account

readOffer(RequestOptions)

Gets offer on database. If none exists, returns an OfferResponse with undefined.

rewrapClientEncryptionKey(string, EncryptionKeyWrapMetadata)

rewraps a client encryption key with new key encryption key

user(string)

Used to read, replace, or delete a specific, existing User by id.

Use .users for creating new users, or querying/reading all users.

Property Details

client

client: CosmosClient

Property Value

containers

Used for creating new containers, or querying/reading all containers.

Use .database(id) to read, replace, or delete a specific, existing Database by id.

Example

Create a new container

const {body: containerDefinition, container} = await client.database("<db id>").containers.create({id: "<container id>"});
containers: Containers

Property Value

id

id: string

Property Value

string

url

Returns a reference URL to the resource. Used for linking in Permissions.

string url

Property Value

string

users

Used for creating new users, or querying/reading all users.

Use .user(id) to read, replace, or delete a specific, existing User by id.

users: Users

Property Value

Method Details

container(string)

Used to read, replace, or delete a specific, existing Database by id.

Use .containers creating new containers, or querying/reading all containers.

Example

Delete a container

await client.database("<db id>").container("<container id>").delete();
function container(id: string): Container

Parameters

id

string

Returns

createClientEncryptionKey(string, AEAD_AES_256_CBC_HMAC_SHA256, EncryptionKeyWrapMetadata)

Create Encryption key for database account

function createClientEncryptionKey(clientEncryptionKeyId: string, encryptionAlgorithm: AEAD_AES_256_CBC_HMAC_SHA256, keyWrapMetadata: EncryptionKeyWrapMetadata): Promise<ClientEncryptionKeyResponse>

Parameters

clientEncryptionKeyId

string

encryptionAlgorithm
AEAD_AES_256_CBC_HMAC_SHA256
keyWrapMetadata
EncryptionKeyWrapMetadata

Returns

delete(RequestOptions)

Delete the given Database.

function delete(options?: RequestOptions): Promise<DatabaseResponse>

Parameters

options
RequestOptions

Returns

Promise<DatabaseResponse>

read(RequestOptions)

Read the definition of the given Database.

function read(options?: RequestOptions): Promise<DatabaseResponse>

Parameters

options
RequestOptions

Returns

Promise<DatabaseResponse>

readClientEncryptionKey(string)

Read Encryption key for database account

function readClientEncryptionKey(clientEncryptionKeyId: string): Promise<ClientEncryptionKeyResponse>

Parameters

clientEncryptionKeyId

string

Returns

readOffer(RequestOptions)

Gets offer on database. If none exists, returns an OfferResponse with undefined.

function readOffer(options?: RequestOptions): Promise<OfferResponse>

Parameters

options
RequestOptions

Returns

Promise<OfferResponse>

rewrapClientEncryptionKey(string, EncryptionKeyWrapMetadata)

rewraps a client encryption key with new key encryption key

function rewrapClientEncryptionKey(clientEncryptionKeyId: string, newKeyWrapMetadata: EncryptionKeyWrapMetadata): Promise<ClientEncryptionKeyResponse>

Parameters

clientEncryptionKeyId

string

newKeyWrapMetadata
EncryptionKeyWrapMetadata

new encryption key wrap metadata

Returns

rewrapped client encryption key with new customer managed key

user(string)

Used to read, replace, or delete a specific, existing User by id.

Use .users for creating new users, or querying/reading all users.

function user(id: string): User

Parameters

id

string

Returns