Udostępnij za pomocą


TableClient class

Obiekt TableClient reprezentuje klienta w usłudze Azure Tables, co umożliwia wykonywanie operacji w jednej tabeli.

Konstruktory

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Tworzy nowe wystąpienie klasy TableClient.

TableClient(string, string, SASCredential, TableServiceClientOptions)

Tworzy nowe wystąpienie klasy TableClient.

TableClient(string, string, TableServiceClientOptions)

Tworzy wystąpienie klasy TableClient.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

Tworzy nowe wystąpienie klasy TableClient.

Właściwości

pipeline

Reprezentuje potok do tworzenia żądania HTTP do adresu URL. Potoki mogą mieć wiele zasad do zarządzania manipulowaniem każdym żądaniem przed i po jego wykonaniu na serwerze.

tableName

Nazwa tabeli do wykonania operacji.

url

Adres URL konta tabeli

Metody

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

Wstaw jednostkę w tabeli.

createTable(OperationOptions)

Tworzy tabelę z tabelą tableName przekazaną do konstruktora klienta

deleteEntity(string, string, DeleteTableEntityOptions)

Usuwa określoną jednostkę w tabeli.

deleteTable(OperationOptions)

Trwale usuwa bieżącą tabelę ze wszystkimi jej jednostkami.

fromConnectionString(string, string, TableServiceClientOptions)

Tworzy wystąpienie klasy TableClient na podstawie parametrów połączenia.

getAccessPolicy(OperationOptions)

Pobiera szczegółowe informacje o wszystkich przechowywanych zasadach dostępu określonych w tabeli, które mogą być używane z sygnaturami dostępu współdzielonego.

getEntity<T>(string, string, GetTableEntityOptions)

Zwraca pojedynczą jednostkę w tabeli.

listEntities<T>(ListTableEntitiesOptions)

Wykonuje zapytania o jednostki w tabeli.

setAccessPolicy(SignedIdentifier[], OperationOptions)

Ustawia przechowywane zasady dostępu dla tabeli, które mogą być używane z sygnaturami dostępu współdzielonego.

submitTransaction(TransactionAction[], OperationOptions)

Przesyła transakcję składającą się z zestawu akcji. Możesz podać akcje jako listę lub użyć TableTransaction, aby ułatwić tworzenie transakcji.

Przykładowe użycie:

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);

Przykładowe użycie za pomocą funkcji 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)

Zaktualizuj jednostkę w tabeli.

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

Upsert jednostki w tabeli.

Szczegóły konstruktora

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Tworzy nowe wystąpienie klasy TableClient.

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

Parametry

url

string

Adres URL konta usługi, który jest celem żądanej operacji, na przykład "https://myaccount.table.core.windows.net".

tableName

string

nazwa tabeli

credential
NamedKeyCredential

NamedKeyCredential używany do uwierzytelniania żądań. Obsługiwane tylko dla węzła

options
TableServiceClientOptions

Fakultatywny. Opcje konfigurowania potoku HTTP.

Przykład użycia nazwy/klucza konta:

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)

Tworzy nowe wystąpienie klasy TableClient.

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

Parametry

url

string

Adres URL konta usługi, który jest celem żądanej operacji, na przykład "https://myaccount.table.core.windows.net".

tableName

string

nazwa tabeli

credential
SASCredential

Sygnatura dostępu współdzielonego używana do uwierzytelniania żądań

options
TableServiceClientOptions

Fakultatywny. Opcje konfigurowania potoku HTTP.

Przykład użycia tokenu 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)

Tworzy wystąpienie klasy TableClient.

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

Parametry

url

string

Ciąg klienta wskazujący usługę tabel usługi Azure Storage, taką jak "https://myaccount.table.core.windows.net". Możesz dołączyć sygnaturę dostępu współdzielonego, taką jak "https://myaccount.table.core.windows.net?sasString".

tableName

string

nazwa tabeli

options
TableServiceClientOptions

Opcje konfigurowania potoku HTTP.

Przykład dołączania tokenu 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)

Tworzy nowe wystąpienie klasy TableClient.

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

Parametry

url

string

Adres URL konta usługi, który jest celem żądanej operacji, na przykład "https://myaccount.table.core.windows.net".

tableName

string

nazwa tabeli

credential
TokenCredential

Poświadczenia usługi Azure Active Directory używane do uwierzytelniania żądań

options
TableServiceClientOptions

Fakultatywny. Opcje konfigurowania potoku HTTP.

Przykład użycia poświadczeń usługi 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,
);

Szczegóły właściwości

pipeline

Reprezentuje potok do tworzenia żądania HTTP do adresu URL. Potoki mogą mieć wiele zasad do zarządzania manipulowaniem każdym żądaniem przed i po jego wykonaniu na serwerze.

pipeline: Pipeline

Wartość właściwości

tableName

Nazwa tabeli do wykonania operacji.

tableName: string

Wartość właściwości

string

url

Adres URL konta tabeli

url: string

Wartość właściwości

string

Szczegóły metody

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

Wstaw jednostkę w tabeli.

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

Parametry

entity

TableEntity<T>

Właściwości jednostki tabeli.

options
OperationOptions

Parametry opcji.

Przykład tworzenia jednostki

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);

Zwraca

createTable(OperationOptions)

Tworzy tabelę z tabelą tableName przekazaną do konstruktora klienta

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

Parametry

options
OperationOptions

Parametry opcji.

Przykład tworzenia tabeli

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();

Zwraca

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

Usuwa określoną jednostkę w tabeli.

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

Parametry

partitionKey

string

Klucz partycji jednostki.

rowKey

string

Klucz wiersza jednostki.

options
DeleteTableEntityOptions

Parametry opcji.

Przykład usuwania jednostki

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>");

Zwraca

deleteTable(OperationOptions)

Trwale usuwa bieżącą tabelę ze wszystkimi jej jednostkami.

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

Parametry

options
OperationOptions

Parametry opcji.

Przykład usuwania tabeli

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();

Zwraca

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

Tworzy wystąpienie klasy TableClient na podstawie parametrów połączenia.

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

Parametry

connectionString

string

Parametry połączenia konta lub parametry połączenia sygnatury dostępu współdzielonego konta usługi Azure Storage. [ Uwaga — parametry połączenia konta mogą być używane tylko w środowisku uruchomieniowym NODE.JS. ] Przykład parametrów połączenia konta — przykład parametrów połączenia sygnatury dostępu współdzielonego DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.netBlobEndpoint=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

Opcje konfigurowania potoku HTTP.

Zwraca

Nowy obiekt TableClient z podanych parametrów połączenia.

getAccessPolicy(OperationOptions)

Pobiera szczegółowe informacje o wszystkich przechowywanych zasadach dostępu określonych w tabeli, które mogą być używane z sygnaturami dostępu współdzielonego.

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

Parametry

options
OperationOptions

Parametry opcji.

Zwraca

getEntity<T>(string, string, GetTableEntityOptions)

Zwraca pojedynczą jednostkę w tabeli.

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

Parametry

partitionKey

string

Klucz partycji jednostki.

rowKey

string

Klucz wiersza jednostki.

options
GetTableEntityOptions

Parametry opcji.

Przykład pobierania jednostki

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}`);

Zwraca

listEntities<T>(ListTableEntitiesOptions)

Wykonuje zapytania o jednostki w tabeli.

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

Parametry

options
ListTableEntitiesOptions

Parametry opcji.

Przykładowe wyświetlanie listy jednostek

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}`);
}

Zwraca

setAccessPolicy(SignedIdentifier[], OperationOptions)

Ustawia przechowywane zasady dostępu dla tabeli, które mogą być używane z sygnaturami dostępu współdzielonego.

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

Parametry

tableAcl

SignedIdentifier[]

Lista kontroli dostępu dla tabeli.

options
OperationOptions

Parametry opcji.

Zwraca

submitTransaction(TransactionAction[], OperationOptions)

Przesyła transakcję składającą się z zestawu akcji. Możesz podać akcje jako listę lub użyć TableTransaction, aby ułatwić tworzenie transakcji.

Przykładowe użycie:

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);

Przykładowe użycie za pomocą funkcji 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>

Parametry

actions

TransactionAction[]

krotka zawierająca akcję do wykonania, oraz jednostkę do wykonania akcji za pomocą polecenia

options
OperationOptions

Opcje żądania.

Zwraca

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

Zaktualizuj jednostkę w tabeli.

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

Parametry

entity

TableEntity<T>

Właściwości jednostki do zaktualizowania.

mode
UpdateMode

Różne tryby aktualizowania jednostki: — Scalanie: aktualizuje jednostkę, aktualizując właściwości jednostki bez zastępowania istniejącej jednostki. — Zastąp: aktualizuje istniejącą jednostkę, zastępując całą jednostkę.

options
UpdateTableEntityOptions

Parametry opcji.

Przykład aktualizowania jednostki

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");

Zwraca

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

Upsert jednostki w tabeli.

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

Parametry

entity

TableEntity<T>

Właściwości jednostki tabeli.

mode
UpdateMode

Różne tryby aktualizowania jednostki: — Scalanie: aktualizuje jednostkę, aktualizując właściwości jednostki bez zastępowania istniejącej jednostki. — Zastąp: aktualizuje istniejącą jednostkę, zastępując całą jednostkę.

options
OperationOptions

Parametry opcji.

Przykład upserting jednostki

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");

Zwraca