Database class
既存のデータベースを読み取りまたは削除するための操作。
新しいデータベースを作成し、すべてのデータベースの読み取り/クエリを実行する方法については、「データベースの」を参照してください。client.databases
を使用します。
注: これらすべての操作は、固定予算に対して呼び出しを行います。
これらの呼び出しがアプリケーションと共にサブリニアにスケーリングされるようにシステムを設計する必要があります。
たとえば、1 回の database.read()
呼び出しの前に item.read()
を呼び出して、データベースが存在することを確認しないでください。これは、アプリケーションの起動時に 1 回行います。
プロパティ
client | |
containers | 新しいコンテナーの作成、またはすべてのコンテナーのクエリ/読み取りに使用されます。
例 新しいコンテナーを作成する
|
id | |
url | リソースへの参照 URL を返します。 アクセス許可のリンクに使用されます。 例
|
users | 新しいユーザーの作成、またはすべてのユーザーのクエリ/読み取りに使用されます。
|
メソッド
container(string) | 既存の特定の Database を ID で読み取り、置換、または削除するために使用されます。
例 コンテナーを削除する
|
create |
データベース アカウントの暗号化キーを作成する 例
|
delete(Request |
指定されたデータベースを削除します。 例
|
read(Request |
指定されたデータベースの定義を読み取ります。 例
|
read |
データベースアカウントの暗号化キーの読み取り 例
|
read |
データベースのオファーを取得します。 存在しない場合は、未定義の OfferResponse を返します。 例 データベースでオファーを読む
|
rewrap |
クライアント暗号化キーを新しいキー暗号化キーで再ラップします 例
|
user(string) | 既存の特定の ユーザー を ID で読み取り、置換、または削除するために使用されます。
例 ユーザーを削除する
|
プロパティの詳細
client
containers
新しいコンテナーの作成、またはすべてのコンテナーのクエリ/読み取りに使用されます。
.database(id)
を使用して、既存の特定の Database を ID で読み取り、置換、または削除します。
例
新しいコンテナーを作成する
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { body: containerDefinition, container } = await client
.database("<db id>")
.containers.create({ id: "<container id>" });
containers: Containers
プロパティ値
id
id: string
プロパティ値
string
url
リソースへの参照 URL を返します。 アクセス許可のリンクに使用されます。
例
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const url = database.url;
string url
プロパティ値
string
users
メソッドの詳細
container(string)
既存の特定の Database を ID で読み取り、置換、または削除するために使用されます。
.containers
新しいコンテナーの作成、またはすべてのコンテナーのクエリ/読み取りを使用します。
例
コンテナーを削除する
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
await client.database("<db id>").container("<container id>").delete();
function container(id: string): Container
パラメーター
- id
-
string
戻り値
createClientEncryptionKey(string, AEAD_AES_256_CBC_HMAC_SHA256, EncryptionKeyWrapMetadata)
データベース アカウントの暗号化キーを作成する
例
import { ClientSecretCredential } from "@azure/identity";
import {
AzureKeyVaultEncryptionKeyResolver,
CosmosClient,
EncryptionKeyWrapMetadata,
EncryptionKeyResolverName,
KeyEncryptionAlgorithm,
EncryptionAlgorithm,
} from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
endpoint,
key,
clientEncryptionOptions: {
keyEncryptionKeyResolver: keyResolver,
},
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });
const metadata: EncryptionKeyWrapMetadata = {
type: EncryptionKeyResolverName.AzureKeyVault,
name: "<key-name>",
value: "<key-vault-url>",
algorithm: KeyEncryptionAlgorithm.RSA_OAEP,
};
await database.createClientEncryptionKey(
"<cek-id>",
EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA256,
metadata,
);
function createClientEncryptionKey(clientEncryptionKeyId: string, encryptionAlgorithm: AEAD_AES_256_CBC_HMAC_SHA256, keyWrapMetadata: EncryptionKeyWrapMetadata): Promise<ClientEncryptionKeyResponse>
パラメーター
- clientEncryptionKeyId
-
string
- encryptionAlgorithm
- AEAD_AES_256_CBC_HMAC_SHA256
- keyWrapMetadata
- EncryptionKeyWrapMetadata
戻り値
Promise<ClientEncryptionKeyResponse>
delete(RequestOptions)
指定されたデータベースを削除します。
例
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
await client.database("<id here>").delete();
function delete(options?: RequestOptions): Promise<DatabaseResponse>
パラメーター
- options
- RequestOptions
戻り値
Promise<DatabaseResponse>
read(RequestOptions)
指定されたデータベースの定義を読み取ります。
例
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { resource: database } = await client.database("<db id>").read();
function read(options?: RequestOptions): Promise<DatabaseResponse>
パラメーター
- options
- RequestOptions
戻り値
Promise<DatabaseResponse>
readClientEncryptionKey(string)
データベースアカウントの暗号化キーの読み取り
例
import { ClientSecretCredential } from "@azure/identity";
import { AzureKeyVaultEncryptionKeyResolver, CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
endpoint,
key,
clientEncryptionOptions: {
keyEncryptionKeyResolver: keyResolver,
},
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });
const { resource: clientEncryptionKey } = await database.readClientEncryptionKey("<cek-id>");
function readClientEncryptionKey(clientEncryptionKeyId: string): Promise<ClientEncryptionKeyResponse>
パラメーター
- clientEncryptionKeyId
-
string
戻り値
Promise<ClientEncryptionKeyResponse>
readOffer(RequestOptions)
データベースのオファーを取得します。 存在しない場合は、未定義の OfferResponse を返します。
例
データベースでオファーを読む
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { resource: offer } = await client.database("<db id>").readOffer();
function readOffer(options?: RequestOptions): Promise<OfferResponse>
パラメーター
- options
- RequestOptions
戻り値
Promise<OfferResponse>
rewrapClientEncryptionKey(string, EncryptionKeyWrapMetadata)
クライアント暗号化キーを新しいキー暗号化キーで再ラップします
例
import { ClientSecretCredential } from "@azure/identity";
import {
AzureKeyVaultEncryptionKeyResolver,
CosmosClient,
EncryptionKeyWrapMetadata,
EncryptionKeyResolverName,
KeyEncryptionAlgorithm,
} from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
endpoint,
key,
clientEncryptionOptions: {
keyEncryptionKeyResolver: keyResolver,
},
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });
const newMetadata: EncryptionKeyWrapMetadata = {
type: EncryptionKeyResolverName.AzureKeyVault,
name: "<key-name>",
value: "<key-vault-url>",
algorithm: KeyEncryptionAlgorithm.RSA_OAEP,
};
await database.rewrapClientEncryptionKey("<new-cek-id>", newMetadata);
function rewrapClientEncryptionKey(clientEncryptionKeyId: string, newKeyWrapMetadata: EncryptionKeyWrapMetadata): Promise<ClientEncryptionKeyResponse>
パラメーター
- clientEncryptionKeyId
-
string
- newKeyWrapMetadata
- EncryptionKeyWrapMetadata
新しい暗号化キー ラップ メタデータ
戻り値
Promise<ClientEncryptionKeyResponse>
新しいカスタマー管理キーで再ラップされたクライアント暗号化キー
user(string)
既存の特定の ユーザー を ID で読み取り、置換、または削除するために使用されます。
.users
を使用して、新しいユーザーを作成したり、すべてのユーザーのクエリや読み取りを行ったりします。
例
ユーザーを削除する
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
await client.database("<db id>").user("<user id>").delete();
function user(id: string): User
パラメーター
- id
-
string