Freigeben über


TableClient class

Ein TableClient stellt einen Client für den Azure Tables-Dienst dar, mit dem Sie Vorgänge für eine einzelne Tabelle ausführen können.

Konstruktoren

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Erstellt eine neue Instanz der TableClient-Klasse.

TableClient(string, string, SASCredential, TableServiceClientOptions)

Erstellt eine neue Instanz der TableClient-Klasse.

TableClient(string, string, TableServiceClientOptions)

Erstellt eine Instanz von TableClient.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

Erstellt eine neue Instanz der TableClient-Klasse.

Eigenschaften

pipeline

Stellt eine Pipeline zum Erstellen einer HTTP-Anforderung an eine URL dar. Pipelines können über mehrere Richtlinien verfügen, um die Bearbeitung jeder Anforderung vor und nach dem Ausführen an den Server zu verwalten.

tableName

Der Name der Tabelle, für die Vorgänge ausgeführt werden sollen.

url

Tabellenkonto-URL

Methoden

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

Fügen Sie die Entität in die Tabelle ein.

createTable(OperationOptions)

Erstellt eine Tabelle mit dem an den Clientkonstruktor übergebenen TableName

deleteEntity(string, string, DeleteTableEntityOptions)

Löscht die angegebene Entität in der Tabelle.

deleteTable(OperationOptions)

Löscht die aktuelle Tabelle dauerhaft mit allen zugehörigen Entitäten.

fromConnectionString(string, string, TableServiceClientOptions)

Erstellt eine Instanz von TableClient aus verbindungszeichenfolge.

getAccessPolicy(OperationOptions)

Ruft Details zu allen gespeicherten Zugriffsrichtlinien ab, die in der Tabelle angegeben sind, die mit Freigegebenen Zugriffssignaturen verwendet werden können.

getEntity<T>(string, string, GetTableEntityOptions)

Gibt eine einzelne Entität in der Tabelle zurück.

listEntities<T>(ListTableEntitiesOptions)

Fragt Entitäten in einer Tabelle ab.

setAccessPolicy(SignedIdentifier[], OperationOptions)

Legt gespeicherte Zugriffsrichtlinien für die Tabelle fest, die mit Signaturen für den freigegebenen Zugriff verwendet werden kann.

submitTransaction(TransactionAction[], OperationOptions)

Sendet eine Transaktion, die aus einer Gruppe von Aktionen besteht. Sie können die Aktionen als Liste bereitstellen oder TableTransaction- verwenden, um die Transaktion zu erstellen.

Beispielverwendung:

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

Beispielverwendung mit 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)

Aktualisieren sie eine Entität in der Tabelle.

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

Upsert eine Entität in der Tabelle.

Details zum Konstruktor

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Erstellt eine neue Instanz der TableClient-Klasse.

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

Parameter

url

string

Die URL des Dienstkontos, das das Ziel des gewünschten Vorgangs ist, z. B. "https://myaccount.table.core.windows.net".

tableName

string

der Name der Tabelle

credential
NamedKeyCredential

NamedKeyCredential, die zum Authentifizieren von Anforderungen verwendet wird. Nur für Knoten unterstützt

options
TableServiceClientOptions

Wahlfrei. Optionen zum Konfigurieren der HTTP-Pipeline.

Beispiel für die Verwendung eines Kontonamens/Schlüssels:

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)

Erstellt eine neue Instanz der TableClient-Klasse.

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

Parameter

url

string

Die URL des Dienstkontos, das das Ziel des gewünschten Vorgangs ist, z. B. "https://myaccount.table.core.windows.net".

tableName

string

der Name der Tabelle

credential
SASCredential

SASCredential für die Authentifizierung von Anforderungen

options
TableServiceClientOptions

Wahlfrei. Optionen zum Konfigurieren der HTTP-Pipeline.

Beispiel für die Verwendung eines SAS-Tokens:

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)

Erstellt eine Instanz von TableClient.

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

Parameter

url

string

Eine Clientzeichenfolge, die auf den Azure Storage-Tabellendienst verweist, z. B. "https://myaccount.table.core.windows.net". Sie können eine SAS anfügen, z. B. "https://myaccount.table.core.windows.net?sasString".

tableName

string

der Name der Tabelle

options
TableServiceClientOptions

Optionen zum Konfigurieren der HTTP-Pipeline.

Beispiel zum Anfügen eines SAS-Tokens:

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)

Erstellt eine neue Instanz der TableClient-Klasse.

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

Parameter

url

string

Die URL des Dienstkontos, das das Ziel des gewünschten Vorgangs ist, z. B. "https://myaccount.table.core.windows.net".

tableName

string

der Name der Tabelle

credential
TokenCredential

Azure Active Directory-Anmeldeinformationen zum Authentifizieren von Anforderungen

options
TableServiceClientOptions

Wahlfrei. Optionen zum Konfigurieren der HTTP-Pipeline.

Beispiel für die Verwendung von Azure Active Directory-Anmeldeinformationen:

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

Details zur Eigenschaft

pipeline

Stellt eine Pipeline zum Erstellen einer HTTP-Anforderung an eine URL dar. Pipelines können über mehrere Richtlinien verfügen, um die Bearbeitung jeder Anforderung vor und nach dem Ausführen an den Server zu verwalten.

pipeline: Pipeline

Eigenschaftswert

tableName

Der Name der Tabelle, für die Vorgänge ausgeführt werden sollen.

tableName: string

Eigenschaftswert

string

url

Tabellenkonto-URL

url: string

Eigenschaftswert

string

Details zur Methode

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

Fügen Sie die Entität in die Tabelle ein.

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

Parameter

entity

TableEntity<T>

Die Eigenschaften für die Tabellenentität.

options
OperationOptions

Die Optionsparameter.

Beispiel zum Erstellen einer Entität

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

Gibt zurück

createTable(OperationOptions)

Erstellt eine Tabelle mit dem an den Clientkonstruktor übergebenen TableName

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

Parameter

options
OperationOptions

Die Optionsparameter.

Beispiel zum Erstellen einer Tabelle

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

Gibt zurück

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

Löscht die angegebene Entität in der Tabelle.

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

Parameter

partitionKey

string

Der Partitionsschlüssel der Entität.

rowKey

string

Der Zeilenschlüssel der Entität.

options
DeleteTableEntityOptions

Die Optionsparameter.

Beispiel zum Löschen einer Entität

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

Gibt zurück

deleteTable(OperationOptions)

Löscht die aktuelle Tabelle dauerhaft mit allen zugehörigen Entitäten.

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

Parameter

options
OperationOptions

Die Optionsparameter.

Beispiel zum Löschen einer Tabelle

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

Gibt zurück

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

Erstellt eine Instanz von TableClient aus verbindungszeichenfolge.

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

Parameter

connectionString

string

Kontoverbindungszeichenfolge oder SAS-Verbindungszeichenfolge eines Azure-Speicherkontos. [ Hinweis : Kontoverbindungszeichenfolge kann nur in NODE.JS Laufzeit verwendet werden. ] Beispiel für kontoverbindungszeichenfolge - beispiel für DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net SAS-Verbindungszeichenfolge - 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

Optionen zum Konfigurieren der HTTP-Pipeline.

Gibt zurück

Ein neuer TableClient aus der angegebenen Verbindungszeichenfolge.

getAccessPolicy(OperationOptions)

Ruft Details zu allen gespeicherten Zugriffsrichtlinien ab, die in der Tabelle angegeben sind, die mit Freigegebenen Zugriffssignaturen verwendet werden können.

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

Parameter

options
OperationOptions

Die Optionsparameter.

Gibt zurück

getEntity<T>(string, string, GetTableEntityOptions)

Gibt eine einzelne Entität in der Tabelle zurück.

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

Parameter

partitionKey

string

Der Partitionsschlüssel der Entität.

rowKey

string

Der Zeilenschlüssel der Entität.

options
GetTableEntityOptions

Die Optionsparameter.

Beispiel für das Abrufen einer Entität

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

Gibt zurück

listEntities<T>(ListTableEntitiesOptions)

Fragt Entitäten in einer Tabelle ab.

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

Parameter

options
ListTableEntitiesOptions

Die Optionsparameter.

Beispiel zum Auflisten von Entitäten

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

Gibt zurück

setAccessPolicy(SignedIdentifier[], OperationOptions)

Legt gespeicherte Zugriffsrichtlinien für die Tabelle fest, die mit Signaturen für den freigegebenen Zugriff verwendet werden kann.

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

Parameter

tableAcl

SignedIdentifier[]

Die Zugriffssteuerungsliste für die Tabelle.

options
OperationOptions

Die Optionsparameter.

Gibt zurück

submitTransaction(TransactionAction[], OperationOptions)

Sendet eine Transaktion, die aus einer Gruppe von Aktionen besteht. Sie können die Aktionen als Liste bereitstellen oder TableTransaction- verwenden, um die Transaktion zu erstellen.

Beispielverwendung:

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

Beispielverwendung mit 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>

Parameter

actions

TransactionAction[]

Tupel, das die auszuführende Aktion enthält, und die Entität zum Ausführen der Aktion mit

options
OperationOptions

Optionen für die Anforderung.

Gibt zurück

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

Aktualisieren sie eine Entität in der Tabelle.

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

Parameter

entity

TableEntity<T>

Die Eigenschaften der Entität, die aktualisiert werden soll.

mode
UpdateMode

Die verschiedenen Modi zum Aktualisieren der Entität: - Zusammenführen: Aktualisiert eine Entität, indem die Eigenschaften der Entität aktualisiert werden, ohne die vorhandene Entität zu ersetzen. - Ersetzen: Aktualisiert eine vorhandene Entität, indem die gesamte Entität ersetzt wird.

options
UpdateTableEntityOptions

Die Optionsparameter.

Beispiel für die Aktualisierung einer Entität

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

Gibt zurück

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

Upsert eine Entität in der Tabelle.

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

Parameter

entity

TableEntity<T>

Die Eigenschaften für die Tabellenentität.

mode
UpdateMode

Die verschiedenen Modi zum Aktualisieren der Entität: - Zusammenführen: Aktualisiert eine Entität, indem die Eigenschaften der Entität aktualisiert werden, ohne die vorhandene Entität zu ersetzen. - Ersetzen: Aktualisiert eine vorhandene Entität, indem die gesamte Entität ersetzt wird.

options
OperationOptions

Die Optionsparameter.

Beispiel zum Upserting einer Entität

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

Gibt zurück