次の方法で共有


TableClient class

TableClient は、Azure Tables サービスへのクライアントを表し、1 つのテーブルに対して操作を実行できます。

コンストラクター

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

TableClient クラスの新しいインスタンスを作成します。

TableClient(string, string, SASCredential, TableServiceClientOptions)

TableClient クラスの新しいインスタンスを作成します。

TableClient(string, string, TableServiceClientOptions)

TableClient のインスタンスを作成します。

TableClient(string, string, TokenCredential, TableServiceClientOptions)

TableClient クラスの新しいインスタンスを作成します。

プロパティ

pipeline

URL への HTTP 要求を行うパイプラインを表します。 パイプラインには、サーバーに対して行われる前と後の各要求の操作を管理するための複数のポリシーを含めることができます。

tableName

操作を実行するテーブルの名前。

url

テーブル アカウントの URL

メソッド

createEntity<T>(TableEntity<T>, OperationOptions)

テーブルにエンティティを挿入します。

createTable(OperationOptions)

クライアント コンストラクターに渡された tableName を使用してテーブルを作成します。

deleteEntity(string, string, DeleteTableEntityOptions)

テーブル内の指定したエンティティを削除します。

deleteTable(OperationOptions)

現在のテーブルとそのすべてのエンティティを完全に削除します。

fromConnectionString(string, string, TableServiceClientOptions)

接続文字列から TableClient のインスタンスを作成します。

getAccessPolicy(OperationOptions)

Shared Access Signature で使用できるテーブルで指定された、保存されているアクセス ポリシーに関する詳細を取得します。

getEntity<T>(string, string, GetTableEntityOptions)

テーブル内の 1 つのエンティティを返します。

listEntities<T>(ListTableEntitiesOptions)

テーブル内のエンティティを照会します。

setAccessPolicy(SignedIdentifier[], OperationOptions)

Shared Access Signature で使用できるテーブルの格納されたアクセス ポリシーを設定します。

submitTransaction(TransactionAction[], OperationOptions)

一連のアクションで構成されるトランザクションを送信します。 アクションをリストとして指定することも、TableTransaction 使用してトランザクションの構築に役立てることもできます。

使用例:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TransactionAction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const actions: TransactionAction[] = [
  ["create", { partitionKey: "p1", rowKey: "1", data: "test1" }],
  ["delete", { partitionKey: "p1", rowKey: "2" }],
  ["update", { partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge"],
];
const result = await client.submitTransaction(actions);

TableTransaction での使用例:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TableTransaction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const transaction = new TableTransaction();

// Call the available action in the TableTransaction object
transaction.createEntity({ partitionKey: "p1", rowKey: "1", data: "test1" });
transaction.deleteEntity("p1", "2");
transaction.updateEntity({ partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge");

// submitTransaction with the actions list on the transaction.
const result = await client.submitTransaction(transaction.actions);
updateEntity<T>(TableEntity<T>, UpdateMode, UpdateTableEntityOptions)

テーブル内のエンティティを更新します。

upsertEntity<T>(TableEntity<T>, UpdateMode, OperationOptions)

テーブル内のエンティティをアップサートします。

コンストラクターの詳細

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

TableClient クラスの新しいインスタンスを作成します。

new TableClient(url: string, tableName: string, credential: NamedKeyCredential, options?: TableServiceClientOptions)

パラメーター

url

string

"https://myaccount.table.core.windows.net"" など、目的の操作のターゲットであるサービス アカウントの URL。

tableName

string

テーブルの名前

credential
NamedKeyCredential

要求の認証に使用される NamedKeyCredential。 Node でのみサポートされます

options
TableServiceClientOptions

随意。 HTTP パイプラインを構成するためのオプション。

アカウント名/キーの使用例:

import { AzureNamedKeyCredential, TableClient } from "@azure/data-tables";

// Enter your storage account name and shared key
const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

// Use AzureNamedKeyCredential with storage account and account key
// AzureNamedKeyCredential is only available in Node.js runtime, not in browsers
const credential = new AzureNamedKeyCredential(account, accountKey);
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

TableClient(string, string, SASCredential, TableServiceClientOptions)

TableClient クラスの新しいインスタンスを作成します。

new TableClient(url: string, tableName: string, credential: SASCredential, options?: TableServiceClientOptions)

パラメーター

url

string

"https://myaccount.table.core.windows.net"" など、目的の操作のターゲットであるサービス アカウントの URL。

tableName

string

テーブルの名前

credential
SASCredential

要求の認証に使用される SASCredential

options
TableServiceClientOptions

随意。 HTTP パイプラインを構成するためのオプション。

SAS トークンの使用例:

import { TableClient, AzureSASCredential } from "@azure/data-tables";

const account = "<account name>";
const sas = "<service Shared Access Signature Token>";
const tableName = "<tableName>";

const clientWithSAS = new TableClient(
  `https://${account}.table.core.windows.net`,
  tableName,
  new AzureSASCredential(sas),
);

TableClient(string, string, TableServiceClientOptions)

TableClient のインスタンスを作成します。

new TableClient(url: string, tableName: string, options?: TableServiceClientOptions)

パラメーター

url

string

"https://myaccount.table.core.windows.net" など、Azure Storage テーブル サービスを指すクライアント文字列。 "https://myaccount.table.core.windows.net?sasString" など、SAS を追加できます。

tableName

string

テーブルの名前

options
TableServiceClientOptions

HTTP パイプラインを構成するためのオプション。

SAS トークンの追加例:

import { TableClient } from "@azure/data-tables";

const account = "<account name>";
const sasToken = "<SAS token>";
const tableName = "<tableName>";

const clientWithSAS = new TableClient(
  `https://${account}.table.core.windows.net?${sasToken}`,
  tableName,
);

TableClient(string, string, TokenCredential, TableServiceClientOptions)

TableClient クラスの新しいインスタンスを作成します。

new TableClient(url: string, tableName: string, credential: TokenCredential, options?: TableServiceClientOptions)

パラメーター

url

string

"https://myaccount.table.core.windows.net"" など、目的の操作のターゲットであるサービス アカウントの URL。

tableName

string

テーブルの名前

credential
TokenCredential

要求の認証に使用される Azure Active Directory 資格情報

options
TableServiceClientOptions

随意。 HTTP パイプラインを構成するためのオプション。

Azure Active Directory 資格情報の使用例:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const credential = new DefaultAzureCredential();
const account = "<account name>";
const tableName = "<tableName>";

const clientWithAAD = new TableClient(
  `https://${account}.table.core.windows.net`,
  tableName,
  credential,
);

プロパティの詳細

pipeline

URL への HTTP 要求を行うパイプラインを表します。 パイプラインには、サーバーに対して行われる前と後の各要求の操作を管理するための複数のポリシーを含めることができます。

pipeline: Pipeline

プロパティ値

tableName

操作を実行するテーブルの名前。

tableName: string

プロパティ値

string

url

テーブル アカウントの URL

url: string

プロパティ値

string

メソッドの詳細

createEntity<T>(TableEntity<T>, OperationOptions)

テーブルにエンティティを挿入します。

function createEntity<T>(entity: TableEntity<T>, options?: OperationOptions): Promise<TableInsertEntityHeaders>

パラメーター

entity

TableEntity<T>

テーブル エンティティのプロパティ。

options
OperationOptions

オプション パラメーター。

エンティティの作成例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const testEntity = {
  partitionKey: "P1",
  rowKey: "R1",
  foo: "foo",
  bar: 123,
};
await client.createEntity(testEntity);

戻り値

createTable(OperationOptions)

クライアント コンストラクターに渡された tableName を使用してテーブルを作成します。

function createTable(options?: OperationOptions): Promise<void>

パラメーター

options
OperationOptions

オプション パラメーター。

テーブルの作成例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

// If the table 'newTable' already exists, createTable doesn't throw
await client.createTable();

戻り値

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

テーブル内の指定したエンティティを削除します。

function deleteEntity(partitionKey: string, rowKey: string, options?: DeleteTableEntityOptions): Promise<TableDeleteEntityHeaders>

パラメーター

partitionKey

string

エンティティのパーティション キー。

rowKey

string

エンティティの行キー。

options
DeleteTableEntityOptions

オプション パラメーター。

エンティティの削除の例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

// deleteEntity deletes the entity that matches exactly the partitionKey and rowKey
await client.deleteEntity("<partitionKey>", "<rowKey>");

戻り値

deleteTable(OperationOptions)

現在のテーブルとそのすべてのエンティティを完全に削除します。

function deleteTable(options?: OperationOptions): Promise<void>

パラメーター

options
OperationOptions

オプション パラメーター。

テーブルの削除の例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

await client.deleteTable();

戻り値

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

接続文字列から TableClient のインスタンスを作成します。

static function fromConnectionString(connectionString: string, tableName: string, options?: TableServiceClientOptions): TableClient

パラメーター

connectionString

string

アカウント接続文字列または Azure ストレージ アカウントの SAS 接続文字列。 [ 注 - アカウント接続文字列は、NODE.JSランタイムでのみ使用できます。 ] アカウント接続文字列の例 - DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net SAS 接続文字列の例 - BlobEndpoint=https://myaccount.table.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString

tableName

string

options
TableServiceClientOptions

HTTP パイプラインを構成するためのオプション。

戻り値

指定された接続文字列からの新しい TableClient。

getAccessPolicy(OperationOptions)

Shared Access Signature で使用できるテーブルで指定された、保存されているアクセス ポリシーに関する詳細を取得します。

function getAccessPolicy(options?: OperationOptions): Promise<GetAccessPolicyResponse>

パラメーター

options
OperationOptions

オプション パラメーター。

戻り値

getEntity<T>(string, string, GetTableEntityOptions)

テーブル内の 1 つのエンティティを返します。

function getEntity<T>(partitionKey: string, rowKey: string, options?: GetTableEntityOptions): Promise<GetTableEntityResponse<TableEntityResult<T>>>

パラメーター

partitionKey

string

エンティティのパーティション キー。

rowKey

string

エンティティの行キー。

options
GetTableEntityOptions

オプション パラメーター。

エンティティの取得例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const entity = await client.getEntity("<partitionKey>", "<rowKey>");
console.log(`Entity: PartitionKey: ${entity.partitionKey} RowKey: ${entity.rowKey}`);

戻り値

listEntities<T>(ListTableEntitiesOptions)

テーブル内のエンティティを照会します。

function listEntities<T>(options?: ListTableEntitiesOptions): PagedAsyncIterableIterator<TableEntityResult<T>, TableEntityResultPage<T>, PageSettings>

パラメーター

options
ListTableEntitiesOptions

オプション パラメーター。

エンティティの一覧表示の例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

let i = 0;
const entities = client.listEntities();
for await (const entity of entities) {
  console.log(`Entity${++i}: PartitionKey: ${entity.partitionKey} RowKey: ${entity.rowKey}`);
}

戻り値

setAccessPolicy(SignedIdentifier[], OperationOptions)

Shared Access Signature で使用できるテーブルの格納されたアクセス ポリシーを設定します。

function setAccessPolicy(tableAcl: SignedIdentifier[], options?: OperationOptions): Promise<TableSetAccessPolicyHeaders>

パラメーター

tableAcl

SignedIdentifier[]

テーブルのアクセス制御リスト。

options
OperationOptions

オプション パラメーター。

戻り値

submitTransaction(TransactionAction[], OperationOptions)

一連のアクションで構成されるトランザクションを送信します。 アクションをリストとして指定することも、TableTransaction 使用してトランザクションの構築に役立てることもできます。

使用例:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TransactionAction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const actions: TransactionAction[] = [
  ["create", { partitionKey: "p1", rowKey: "1", data: "test1" }],
  ["delete", { partitionKey: "p1", rowKey: "2" }],
  ["update", { partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge"],
];
const result = await client.submitTransaction(actions);

TableTransaction での使用例:

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient, TableTransaction } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const transaction = new TableTransaction();

// Call the available action in the TableTransaction object
transaction.createEntity({ partitionKey: "p1", rowKey: "1", data: "test1" });
transaction.deleteEntity("p1", "2");
transaction.updateEntity({ partitionKey: "p1", rowKey: "3", data: "newTest" }, "Merge");

// submitTransaction with the actions list on the transaction.
const result = await client.submitTransaction(transaction.actions);
function submitTransaction(actions: TransactionAction[], options?: OperationOptions): Promise<TableTransactionResponse>

パラメーター

actions

TransactionAction[]

実行するアクションと、アクションを実行するエンティティを含むタプル

options
OperationOptions

要求のオプション。

戻り値

updateEntity<T>(TableEntity<T>, UpdateMode, UpdateTableEntityOptions)

テーブル内のエンティティを更新します。

function updateEntity<T>(entity: TableEntity<T>, mode?: UpdateMode, options?: UpdateTableEntityOptions): Promise<TableUpdateEntityHeaders>

パラメーター

entity

TableEntity<T>

更新するエンティティのプロパティ。

mode
UpdateMode

エンティティを更新するためのさまざまなモード: - マージ: 既存のエンティティを置き換えずにエンティティのプロパティを更新してエンティティを更新します。 - 置換: エンティティ全体を置き換えることで、既存のエンティティを更新します。

options
UpdateTableEntityOptions

オプション パラメーター。

エンティティの更新の例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const entity = { partitionKey: "p1", rowKey: "r1", bar: "updatedBar" };

// Update uses update mode "Merge" as default
// merge means that update will match a stored entity
// that has the same partitionKey and rowKey as the entity
// passed to the method and then will only update the properties present in it.
// Any other properties that are not defined in the entity passed to updateEntity
// will remain as they are in the service
await client.updateEntity(entity);

// We can also set the update mode to Replace, which will match the entity passed
// to updateEntity with one stored in the service and replace with the new one.
// If there are any missing properties in the entity passed to updateEntity, they
// will be removed from the entity stored in the service
await client.updateEntity(entity, "Replace");

戻り値

upsertEntity<T>(TableEntity<T>, UpdateMode, OperationOptions)

テーブル内のエンティティをアップサートします。

function upsertEntity<T>(entity: TableEntity<T>, mode?: UpdateMode, options?: OperationOptions): Promise<TableMergeEntityHeaders>

パラメーター

entity

TableEntity<T>

テーブル エンティティのプロパティ。

mode
UpdateMode

エンティティを更新するためのさまざまなモード: - マージ: 既存のエンティティを置き換えずにエンティティのプロパティを更新してエンティティを更新します。 - 置換: エンティティ全体を置き換えることで、既存のエンティティを更新します。

options
OperationOptions

オプション パラメーター。

エンティティのアップサートの例

import { DefaultAzureCredential } from "@azure/identity";
import { TableClient } from "@azure/data-tables";

const account = "<account>";
const accountKey = "<accountkey>";
const tableName = "<tableName>";

const credential = new DefaultAzureCredential();
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

const entity = { partitionKey: "p1", rowKey: "r1", bar: "updatedBar" };

// Upsert uses update mode "Merge" as default.
// This behaves similarly to update but creates the entity
// if it doesn't exist in the service
await client.upsertEntity(entity);

// We can also set the update mode to Replace.
// This behaves similarly to update but creates the entity
// if it doesn't exist in the service
await client.upsertEntity(entity, "Replace");

戻り値