Sdílet prostřednictvím


TableClient class

TableClient představuje klienta pro službu Azure Tables, která umožňuje provádět operace v jedné tabulce.

Konstruktory

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Vytvoří novou instanci třídy TableClient.

TableClient(string, string, SASCredential, TableServiceClientOptions)

Vytvoří novou instanci třídy TableClient.

TableClient(string, string, TableServiceClientOptions)

Vytvoří instanci TableClient.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

Vytvoří novou instanci třídy TableClient.

Vlastnosti

pipeline

Představuje kanál pro vytvoření požadavku HTTP na adresu URL. Kanály můžou mít několik zásad pro správu manipulace s jednotlivými požadavky před a po jeho provedení na server.

tableName

Název tabulky pro provádění operací

url

Adresa URL účtu tabulky

Metody

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

Vložte entitu do tabulky.

createTable(OperationOptions)

Vytvoří tabulku s parametrem tableName předaným konstruktoru klienta.

deleteEntity(string, string, DeleteTableEntityOptions)

Odstraní zadanou entitu v tabulce.

deleteTable(OperationOptions)

Trvale odstraní aktuální tabulku se všemi jejími entitami.

fromConnectionString(string, string, TableServiceClientOptions)

Vytvoří instanci TableClient z připojovacího řetězce.

getAccessPolicy(OperationOptions)

Načte podrobnosti o všech uložených zásadách přístupu zadaných v tabulce, kterou lze použít se sdílenými přístupovými podpisy.

getEntity<T>(string, string, GetTableEntityOptions)

Vrátí jednu entitu v tabulce.

listEntities<T>(ListTableEntitiesOptions)

Dotazuje entity v tabulce.

setAccessPolicy(SignedIdentifier[], OperationOptions)

Nastaví uložené zásady přístupu pro tabulku, kterou lze použít se sdílenými přístupovými podpisy.

submitTransaction(TransactionAction[], OperationOptions)

Odešle transakci, která se skládá ze sady akcí. Akce můžete zadat jako seznam nebo můžete použít TableTransaction, které vám pomůžou vytvořit transakci.

Příklad použití:

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

Příklad použití s 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)

Aktualizujte entitu v tabulce.

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

Přenesení entity v tabulce

Podrobnosti konstruktoru

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Vytvoří novou instanci třídy TableClient.

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

Parametry

url

string

Adresa URL účtu služby, který je cílem požadované operace, například "https://myaccount.table.core.windows.net".

tableName

string

název tabulky

credential
NamedKeyCredential

NamedKeyCredential sloužící k ověřování požadavků. Podporováno pouze pro uzel

options
TableServiceClientOptions

Volitelný. Možnosti konfigurace kanálu HTTP

Příklad použití názvu nebo klíče účtu:

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)

Vytvoří novou instanci třídy TableClient.

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

Parametry

url

string

Adresa URL účtu služby, který je cílem požadované operace, například "https://myaccount.table.core.windows.net".

tableName

string

název tabulky

credential
SASCredential

SASCredential sloužící k ověřování požadavků

options
TableServiceClientOptions

Volitelný. Možnosti konfigurace kanálu HTTP

Příklad použití 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)

Vytvoří instanci TableClient.

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

Parametry

url

string

Řetězec klienta odkazující na službu Table Service služby Azure Storage, například "https://myaccount.table.core.windows.net". Můžete připojit SAS, napříkladhttps://myaccount.table.core.windows.net?sasString".

tableName

string

název tabulky

options
TableServiceClientOptions

Možnosti konfigurace kanálu HTTP

Příklad připojení 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)

Vytvoří novou instanci třídy TableClient.

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

Parametry

url

string

Adresa URL účtu služby, který je cílem požadované operace, například "https://myaccount.table.core.windows.net".

tableName

string

název tabulky

credential
TokenCredential

Přihlašovací údaje Azure Active Directory používané k ověřování požadavků

options
TableServiceClientOptions

Volitelný. Možnosti konfigurace kanálu HTTP

Příklad použití přihlašovacích údajů 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,
);

Podrobnosti vlastnosti

pipeline

Představuje kanál pro vytvoření požadavku HTTP na adresu URL. Kanály můžou mít několik zásad pro správu manipulace s jednotlivými požadavky před a po jeho provedení na server.

pipeline: Pipeline

Hodnota vlastnosti

tableName

Název tabulky pro provádění operací

tableName: string

Hodnota vlastnosti

string

url

Adresa URL účtu tabulky

url: string

Hodnota vlastnosti

string

Podrobnosti metody

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

Vložte entitu do tabulky.

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

Parametry

entity

TableEntity<T>

Vlastnosti entity tabulky.

options
OperationOptions

Parametry možností.

Příklad vytvoření entity

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

Návraty

createTable(OperationOptions)

Vytvoří tabulku s parametrem tableName předaným konstruktoru klienta.

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

Parametry

options
OperationOptions

Parametry možností.

Příklad vytvoření tabulky

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

Návraty

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

Odstraní zadanou entitu v tabulce.

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

Parametry

partitionKey

string

Klíč oddílu entity.

rowKey

string

Klíč řádku entity.

options
DeleteTableEntityOptions

Parametry možností.

Příklad odstranění entity

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

Návraty

deleteTable(OperationOptions)

Trvale odstraní aktuální tabulku se všemi jejími entitami.

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

Parametry

options
OperationOptions

Parametry možností.

Příklad odstranění tabulky

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

Návraty

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

Vytvoří instanci TableClient z připojovacího řetězce.

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

Parametry

connectionString

string

Připojovací řetězec účtu nebo připojovací řetězec SAS účtu úložiště Azure. [ Poznámka: Připojovací řetězec účtu lze použít pouze v NODE.JS modulu runtime. ] Příklad připojovacího řetězce účtu – Příklad připojovacího řetězce SAS 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

Možnosti konfigurace kanálu HTTP

Návraty

Nový TableClient z daného připojovacího řetězce.

getAccessPolicy(OperationOptions)

Načte podrobnosti o všech uložených zásadách přístupu zadaných v tabulce, kterou lze použít se sdílenými přístupovými podpisy.

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

Parametry

options
OperationOptions

Parametry možností.

Návraty

getEntity<T>(string, string, GetTableEntityOptions)

Vrátí jednu entitu v tabulce.

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

Parametry

partitionKey

string

Klíč oddílu entity.

rowKey

string

Klíč řádku entity.

options
GetTableEntityOptions

Parametry možností.

Příklad získání entity

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

Návraty

listEntities<T>(ListTableEntitiesOptions)

Dotazuje entity v tabulce.

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

Parametry

options
ListTableEntitiesOptions

Parametry možností.

Příklad výpisu entit

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

Návraty

setAccessPolicy(SignedIdentifier[], OperationOptions)

Nastaví uložené zásady přístupu pro tabulku, kterou lze použít se sdílenými přístupovými podpisy.

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

Parametry

tableAcl

SignedIdentifier[]

Seznam řízení přístupu pro tabulku.

options
OperationOptions

Parametry možností.

Návraty

submitTransaction(TransactionAction[], OperationOptions)

Odešle transakci, která se skládá ze sady akcí. Akce můžete zadat jako seznam nebo můžete použít TableTransaction, které vám pomůžou vytvořit transakci.

Příklad použití:

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

Příklad použití s 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[]

řazená kolekce členů obsahující akci, která se má provést, a entita k provedení akce

options
OperationOptions

Možnosti pro požadavek.

Návraty

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

Aktualizujte entitu v tabulce.

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

Parametry

entity

TableEntity<T>

Vlastnosti entity, která se má aktualizovat.

mode
UpdateMode

Různé režimy aktualizace entity: – Sloučení: Aktualizuje entitu aktualizací vlastností entity bez nahrazení existující entity. - Nahradit: Aktualizuje existující entitu nahrazením celé entity.

options
UpdateTableEntityOptions

Parametry možností.

Příklad aktualizace entity

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

Návraty

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

Přenesení entity v tabulce

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

Parametry

entity

TableEntity<T>

Vlastnosti entity tabulky.

mode
UpdateMode

Různé režimy aktualizace entity: – Sloučení: Aktualizuje entitu aktualizací vlastností entity bez nahrazení existující entity. - Nahradit: Aktualizuje existující entitu nahrazením celé entity.

options
OperationOptions

Parametry možností.

Příklad přenesení entity

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

Návraty