次の方法で共有


Item class

特定の項目に対して操作を実行するために使用されます。

すべてのアイテムに対する操作については、「項目」を参照してください。container.itemsを参照してください。

プロパティ

container
id
url

リソースへの参照 URL を返します。 アクセス許可のリンクに使用されます。

メソッド

delete<T>(RequestOptions)

アイテムを削除します。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。

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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

await container.item("id").delete<TodoItem>();
patch<T>(PatchRequestBody, RequestOptions)

項目に対して JSONPatch を実行します。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

const { resource: patchedItem } = await container.item("id").patch<TodoItem>([
  {
    op: "replace", // Operation type (can be replace, add, remove, set, incr)
    path: "/title", // The path to the property to update
    value: "new-title", // New value for the property
  },
  {
    op: "remove",
    path: "/done",
  },
]);
read<T>(RequestOptions)

項目の定義を読み取る。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。 型 T がクラスの場合、一致プロトタイプがないため、typeof 比較は渡されません。 インターフェイスのみを使用することをお勧めします。

JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。

応答にカスタム型を使用する

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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();
replace(ItemDefinition, RequestOptions)

項目の定義を置き換えます。

JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。

import { CosmosClient, ItemDefinition } 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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const item: ItemDefinition = {
  id: "id",
  title: "new_title",
};

const { resource: replacedItem } = await container.item("id").replace(item);
replace<T>(T, RequestOptions)

項目の定義を置き換えます。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。

JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。

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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

item.done = true;
const { resource: replacedItem } = await container.item("id").replace<TodoItem>(item);

プロパティの詳細

container

container: Container

プロパティ値

id

id: string

プロパティ値

string

url

リソースへの参照 URL を返します。 アクセス許可のリンクに使用されます。

string url

プロパティ値

string

メソッドの詳細

delete<T>(RequestOptions)

アイテムを削除します。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。

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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

await container.item("id").delete<TodoItem>();
function delete<T>(options?: RequestOptions): Promise<ItemResponse<T>>

パラメーター

options
RequestOptions

要求の追加オプション

戻り値

Promise<ItemResponse<T>>

patch<T>(PatchRequestBody, RequestOptions)

項目に対して JSONPatch を実行します。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

const { resource: patchedItem } = await container.item("id").patch<TodoItem>([
  {
    op: "replace", // Operation type (can be replace, add, remove, set, incr)
    path: "/title", // The path to the property to update
    value: "new-title", // New value for the property
  },
  {
    op: "remove",
    path: "/done",
  },
]);
function patch<T>(body: PatchRequestBody, options?: RequestOptions): Promise<ItemResponse<T>>

パラメーター

options
RequestOptions

要求の追加オプション

戻り値

Promise<ItemResponse<T>>

read<T>(RequestOptions)

項目の定義を読み取る。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。 型 T がクラスの場合、一致プロトタイプがないため、typeof 比較は渡されません。 インターフェイスのみを使用することをお勧めします。

JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。

応答にカスタム型を使用する

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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();
function read<T>(options?: RequestOptions): Promise<ItemResponse<T>>

パラメーター

options
RequestOptions

要求の追加オプション

戻り値

Promise<ItemResponse<T>>

replace(ItemDefinition, RequestOptions)

項目の定義を置き換えます。

JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。

import { CosmosClient, ItemDefinition } 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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const item: ItemDefinition = {
  id: "id",
  title: "new_title",
};

const { resource: replacedItem } = await container.item("id").replace(item);
function replace(body: ItemDefinition, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>

パラメーター

body
ItemDefinition

既存の Item'の定義を置き換える定義。

options
RequestOptions

要求の追加オプション

戻り値

replace<T>(T, RequestOptions)

項目の定義を置き換えます。

指定された型 T は、必ずしも SDK によって適用されるとは限りません。 多かれ少なかれプロパティを取得する場合があり、それを適用するのはロジック次第です。

JSON 項目のスキーマは設定されていません。 任意の数のカスタム プロパティを含む場合があります。

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 { container } = await database.containers.createIfNotExists({ id: "Test Container" });

interface TodoItem {
  title: string;
  done: boolean;
  id: string;
}

const { resource: item } = await container.item("id", "<pkValue>").read<TodoItem>();

item.done = true;
const { resource: replacedItem } = await container.item("id").replace<TodoItem>(item);
function replace<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>

パラメーター

body

T

既存の Item'の定義を置き換える定義。

options
RequestOptions

要求の追加オプション

戻り値

Promise<ItemResponse<T>>