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

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í:

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

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

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:

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)

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:

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)

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:

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)

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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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í:

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

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

Parametry

actions

TransactionAction[]

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

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

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

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

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

Návraty