Dela via


TableClient class

En TableClient representerar en klient till Azure Tables-tjänsten så att du kan utföra åtgärder i en enda tabell.

Konstruktorer

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Skapar en ny instans av klassen TableClient.

TableClient(string, string, SASCredential, TableServiceClientOptions)

Skapar en ny instans av klassen TableClient.

TableClient(string, string, TableServiceClientOptions)

Skapar en instans av TableClient.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

Skapar en ny instans av klassen TableClient.

Egenskaper

pipeline

Representerar en pipeline för att göra en HTTP-begäran till en URL. Pipelines kan ha flera principer för att hantera hantering av varje begäran före och efter att den har gjorts till servern.

tableName

Namnet på tabellen som ska utföra åtgärder på.

url

Url för tabellkonto

Metoder

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

Infoga entitet i tabellen.

createTable(OperationOptions)

Skapar en tabell med tableName som skickas till klientkonstruktorn

deleteEntity(string, string, DeleteTableEntityOptions)

Tar bort den angivna entiteten i tabellen.

deleteTable(OperationOptions)

Tar bort den aktuella tabellen permanent med alla dess entiteter.

fromConnectionString(string, string, TableServiceClientOptions)

Skapar en instans av TableClient från anslutningssträngen.

getAccessPolicy(OperationOptions)

Hämtar information om alla lagrade åtkomstprinciper som anges i tabellen som kan användas med signaturer för delad åtkomst.

getEntity<T>(string, string, GetTableEntityOptions)

Returnerar en enskild entitet i tabellen.

listEntities<T>(ListTableEntitiesOptions)

Frågar entiteter i en tabell.

setAccessPolicy(SignedIdentifier[], OperationOptions)

Anger lagrade åtkomstprinciper för tabellen som kan användas med signaturer för delad åtkomst.

submitTransaction(TransactionAction[], OperationOptions)

Skickar en transaktion som består av en uppsättning åtgärder. Du kan ange åtgärderna som en lista eller använda TableTransaction- för att skapa transaktionen.

Exempel på användning:

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

Exempel på användning med 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)

Uppdatera en entitet i tabellen.

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

Upsert en entitet i tabellen.

Konstruktorinformation

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Skapar en ny instans av klassen TableClient.

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

Parametrar

url

string

URL:en för tjänstkontot som är målet för den önskade åtgärden, till exempel "https://myaccount.table.core.windows.net".

tableName

string

tabellens namn

credential
NamedKeyCredential

NamedKeyCredential används för att autentisera begäranden. Stöds endast för Node

options
TableServiceClientOptions

Valfri. Alternativ för att konfigurera HTTP-pipelinen.

Exempel med ett kontonamn/nyckel:

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)

Skapar en ny instans av klassen TableClient.

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

Parametrar

url

string

URL:en för tjänstkontot som är målet för den önskade åtgärden, till exempel "https://myaccount.table.core.windows.net".

tableName

string

tabellens namn

credential
SASCredential

SASCredential används för att autentisera begäranden

options
TableServiceClientOptions

Valfri. Alternativ för att konfigurera HTTP-pipelinen.

Exempel med en SAS-token:

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)

Skapar en instans av TableClient.

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

Parametrar

url

string

En klientsträng som pekar på Azure Storage-tabelltjänsten, till exempel "https://myaccount.table.core.windows.net". Du kan lägga till en SAS, till exempel "https://myaccount.table.core.windows.net?sasString".

tableName

string

tabellens namn

options
TableServiceClientOptions

Alternativ för att konfigurera HTTP-pipelinen.

Exempel som lägger till en SAS-token:

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)

Skapar en ny instans av klassen TableClient.

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

Parametrar

url

string

URL:en för tjänstkontot som är målet för den önskade åtgärden, till exempel "https://myaccount.table.core.windows.net".

tableName

string

tabellens namn

credential
TokenCredential

Azure Active Directory-autentiseringsuppgifter som används för att autentisera begäranden

options
TableServiceClientOptions

Valfri. Alternativ för att konfigurera HTTP-pipelinen.

Exempel med en Azure Active Directory-autentiseringsuppgift:

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

Egenskapsinformation

pipeline

Representerar en pipeline för att göra en HTTP-begäran till en URL. Pipelines kan ha flera principer för att hantera hantering av varje begäran före och efter att den har gjorts till servern.

pipeline: Pipeline

Egenskapsvärde

tableName

Namnet på tabellen som ska utföra åtgärder på.

tableName: string

Egenskapsvärde

string

url

Url för tabellkonto

url: string

Egenskapsvärde

string

Metodinformation

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

Infoga entitet i tabellen.

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

Parametrar

entity

TableEntity<T>

Egenskaperna för tabellentiteten.

options
OperationOptions

Alternativparametrarna.

Exempel på att skapa en entitet

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

Returer

createTable(OperationOptions)

Skapar en tabell med tableName som skickas till klientkonstruktorn

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

Parametrar

options
OperationOptions

Alternativparametrarna.

Exempel på hur du skapar en tabell

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

Returer

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

Tar bort den angivna entiteten i tabellen.

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

Parametrar

partitionKey

string

Partitionsnyckeln för entiteten.

rowKey

string

Entitetens radnyckel.

options
DeleteTableEntityOptions

Alternativparametrarna.

Exempel på borttagning av en entitet

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

Returer

deleteTable(OperationOptions)

Tar bort den aktuella tabellen permanent med alla dess entiteter.

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

Parametrar

options
OperationOptions

Alternativparametrarna.

Exempel på borttagning av en tabell

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

Returer

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

Skapar en instans av TableClient från anslutningssträngen.

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

Parametrar

connectionString

string

Kontoanslutningssträng eller en SAS-anslutningssträng för ett Azure Storage-konto. [ Obs! Kontoanslutningssträngen kan bara användas i NODE.JS körning. ] Exempel på kontoanslutningssträng – DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net EXEMPEL på SAS-anslutningssträng – 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

Alternativ för att konfigurera HTTP-pipelinen.

Returer

En ny TableClient från den angivna anslutningssträngen.

getAccessPolicy(OperationOptions)

Hämtar information om alla lagrade åtkomstprinciper som anges i tabellen som kan användas med signaturer för delad åtkomst.

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

Parametrar

options
OperationOptions

Alternativparametrarna.

Returer

getEntity<T>(string, string, GetTableEntityOptions)

Returnerar en enskild entitet i tabellen.

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

Parametrar

partitionKey

string

Partitionsnyckeln för entiteten.

rowKey

string

Entitetens radnyckel.

options
GetTableEntityOptions

Alternativparametrarna.

Exempel på hur du hämtar en entitet

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

Returer

listEntities<T>(ListTableEntitiesOptions)

Frågar entiteter i en tabell.

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

Parametrar

options
ListTableEntitiesOptions

Alternativparametrarna.

Exempel på entiteter

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

Returer

setAccessPolicy(SignedIdentifier[], OperationOptions)

Anger lagrade åtkomstprinciper för tabellen som kan användas med signaturer för delad åtkomst.

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

Parametrar

tableAcl

SignedIdentifier[]

Åtkomstkontrollistan för tabellen.

options
OperationOptions

Alternativparametrarna.

Returer

submitTransaction(TransactionAction[], OperationOptions)

Skickar en transaktion som består av en uppsättning åtgärder. Du kan ange åtgärderna som en lista eller använda TableTransaction- för att skapa transaktionen.

Exempel på användning:

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

Exempel på användning med 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>

Parametrar

actions

TransactionAction[]

tuppeln som innehåller den åtgärd som ska utföras och entiteten som ska utföra åtgärden med

options
OperationOptions

Alternativ för begäran.

Returer

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

Uppdatera en entitet i tabellen.

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

Parametrar

entity

TableEntity<T>

Egenskaperna för den entitet som ska uppdateras.

mode
UpdateMode

De olika lägena för att uppdatera entiteten: – Sammanslagning: Uppdaterar en entitet genom att uppdatera entitetens egenskaper utan att ersätta den befintliga entiteten. – Ersätt: Uppdaterar en befintlig entitet genom att ersätta hela entiteten.

options
UpdateTableEntityOptions

Alternativparametrarna.

Exempel på uppdatering av en entitet

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

Returer

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

Upsert en entitet i tabellen.

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

Parametrar

entity

TableEntity<T>

Egenskaperna för tabellentiteten.

mode
UpdateMode

De olika lägena för att uppdatera entiteten: – Sammanslagning: Uppdaterar en entitet genom att uppdatera entitetens egenskaper utan att ersätta den befintliga entiteten. – Ersätt: Uppdaterar en befintlig entitet genom att ersätta hela entiteten.

options
OperationOptions

Alternativparametrarna.

Exempel på ökning av en entitet

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

Returer