Database class
기존 데이터베이스를 읽거나 삭제하기 위한 작업입니다.
새 데이터베이스를 만들고 모든 데이터베이스를 읽고 쿼리하려면 데이터베이스 참조하세요. client.databases
사용합니다.
참고: 이러한 모든 작업은 고정 예산에 대해 호출합니다.
이러한 호출이 애플리케이션을 사용하여 하위 선형으로 확장되도록 시스템을 디자인해야 합니다.
예를 들어 데이터베이스가 있는지 확인하기 위해 모든 단일 database.read()
호출하기 전에 item.read()
호출하지 마세요. 애플리케이션 시작 시 이 작업을 한 번 수행합니다.
속성
client | |
containers | 새 컨테이너를 만들거나 모든 컨테이너를 쿼리/읽는 데 사용됩니다.
예제 새 컨테이너 만들기
|
id | |
url | 리소스에 대한 참조 URL을 반환합니다. 사용 권한에서 연결에 사용됩니다. 예제
|
users | 새 사용자를 만들거나 모든 사용자를 쿼리/읽는 데 사용됩니다.
|
메서드
container(string) | ID별로 특정 기존 데이터베이스 읽거나 바꾸거나 삭제하는 데 사용됩니다. 새 컨테이너를 만들거나 모든 컨테이너를 쿼리/읽는 예제 컨테이너 삭제
|
create |
데이터베이스 계정에 대한 암호화 키 만들기 예제
|
delete(Request |
지정된 데이터베이스를 삭제합니다. 예제
|
read(Request |
지정된 데이터베이스의 정의를 읽습니다. 예제
|
read |
데이터베이스 계정에 대한 암호화 키 읽기 예제
|
read |
데이터베이스에 대한 제안을 가져옵니다. 없는 경우 정의되지 않은 OfferResponse를 반환합니다. 예제 데이터베이스에서 제안 읽기
|
rewrap |
클라이언트 암호화 키를 새 키 암호화 키로 다시 래핑합니다. 예제
|
user(string) | ID별로 특정 기존 사용자 읽거나 바꾸거나 삭제하는 데 사용됩니다.
예제 사용자 삭제
|
속성 세부 정보
client
containers
새 컨테이너를 만들거나 모든 컨테이너를 쿼리/읽는 데 사용됩니다.
.database(id)
사용하여 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)
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