Share via


TableClient class

En TableClient representerar en klient för Azure Tables-tjänsten så att du kan utföra åtgärder på 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 manipulering av varje begäran före och efter att den har gjorts till servern.

tableName

Namnet på den tabell som åtgärder ska utföras 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 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[])

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:

const { TableClient } = require("@azure/data-tables");
const connectionString = "<connection-string>"
const tableName = "<tableName>"
const client = TableClient.fromConnectionString(connectionString, tableName);
const actions = [
   ["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);

Exempelanvändning med TableTransaction:

const { TableClient } = require("@azure/data-tables");
const connectionString = "<connection-string>"
const tableName = "<tableName>"
const client = TableClient.fromConnectionString(connectionString, tableName);
const transaction = new TableTransaction();
// Call the available action in the TableTransaction object
transaction.create({partitionKey: "p1", rowKey: "1", data: "test1"});
transaction.delete("p1", "2");
transaction.update({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

namnet på tabellen

credential
NamedKeyCredential

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

options
TableServiceClientOptions

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

Exempel med ett kontonamn/nyckel:

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables");
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

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

namnet på tabellen

credential
SASCredential

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

options
TableServiceClientOptions

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

Exempel med en SAS-token:

const { AzureSASCredential, TableClient } = require("@azure/data-tables");
const account = "<storage account name>";
const sasToken = "<sas-token>";
const tableName = "<table name>";
const sasCredential = new AzureSASCredential(sasToken);

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

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

namnet på tabellen

options
TableServiceClientOptions

Alternativ för att konfigurera HTTP-pipelinen.

Exempel på tillägg av en SAS-token:

const { TableClient } = require("@azure/data-tables");
const account = "<storage account name>";
const sasToken = "<SAS token>";
const tableName = "<table name>";

const client = 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

namnet på tabellen

credential
TokenCredential

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

options
TableServiceClientOptions

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

Exempel med en Azure Active Directory-autentiseringsuppgift:

cons { DefaultAzureCredential } = require("@azure/identity");
const { AzureSASCredential, TableClient } = require("@azure/data-tables");
const account = "<storage account name>";
const sasToken = "<sas-token>";
const tableName = "<table name>";
const credential = new DefaultAzureCredential();

const client = 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 manipulering av varje begäran före och efter att den har gjorts till servern.

pipeline: Pipeline

Egenskapsvärde

tableName

Namnet på den tabell som åtgärder ska utföras 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

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

// partitionKey and rowKey are required properties of the entity to create
// and accepts any other properties
await client.createEntity({partitionKey: "p1", rowKey: "r1", foo: "Hello!"});

Returer

createTable(OperationOptions)

Skapar en tabell med tableName som skickas till klientkonstruktorn

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

Parametrar

options
OperationOptions

Alternativparametrarna.

Exempel på att skapa en tabell

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

// calling create table will create the table used
// to instantiate the TableClient.
// Note: If the table already
// exists this function 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

Radnyckeln för entiteten.

options
DeleteTableEntityOptions

Alternativparametrarna.

Exempel på borttagning av en entitet

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

// deleteEntity deletes the entity that matches
// exactly the partitionKey and rowKey passed as parameters
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

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

// calling deleteTable will delete the table used
// to instantiate the TableClient.
// Note: If the table doesn't exist this function doesn't fail.
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 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

Radnyckeln för entiteten.

options
GetTableEntityOptions

Alternativparametrarna.

Exempel på att hämta en entitet

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

// getEntity will get a single entity stored in the service that
// matches exactly the partitionKey and rowKey used as parameters
// to the method.
const entity = await client.getEntity("<partitionKey>", "<rowKey>");
console.log(entity);

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

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

// list entities returns a AsyncIterableIterator
// this helps consuming paginated responses by
// automatically handling getting the next pages
const entities = client.listEntities();

// this loop will get all the entities from all the pages
// returned by the service
for await (const entity of entities) {
   console.log(entity);
}

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[]

Tabellens Access Control lista.

options
OperationOptions

Alternativparametrarna.

Returer

submitTransaction(TransactionAction[])

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:

const { TableClient } = require("@azure/data-tables");
const connectionString = "<connection-string>"
const tableName = "<tableName>"
const client = TableClient.fromConnectionString(connectionString, tableName);
const actions = [
   ["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);

Exempelanvändning med TableTransaction:

const { TableClient } = require("@azure/data-tables");
const connectionString = "<connection-string>"
const tableName = "<tableName>"
const client = TableClient.fromConnectionString(connectionString, tableName);
const transaction = new TableTransaction();
// Call the available action in the TableTransaction object
transaction.create({partitionKey: "p1", rowKey: "1", data: "test1"});
transaction.delete("p1", "2");
transaction.update({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[]): Promise<TableTransactionResponse>

Parametrar

actions

TransactionAction[]

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

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: – Sammanfoga: Uppdateringar en entitet genom att uppdatera entitetens egenskaper utan att ersätta den befintliga entiteten. – Ersätt: Uppdateringar en befintlig entitet genom att ersätta hela entiteten.

options
UpdateTableEntityOptions

Alternativparametrarna.

Exempel på uppdatering av en entitet

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

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: – Sammanfoga: Uppdateringar en entitet genom att uppdatera entitetens egenskaper utan att ersätta den befintliga entiteten. – Ersätt: Uppdateringar en befintlig entitet genom att ersätta hela entiteten.

options
OperationOptions

Alternativparametrarna.

Exempel på ökning av en entitet

const { AzureNamedKeyCredential, TableClient } = require("@azure/data-tables")
const account = "<storage account name>";
const accountKey = "<account key>"
const tableName = "<table name>";
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);

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

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