Package version:
Creates a new instance of the TableClient class.
The URL of the service account that is the target of the desired operation, such as "https://myaccount.table.core.windows.net".
the name of the table
NamedKeyCredential used to authenticate requests. Only Supported for Node
Optionaloptions: anyOptional. Options to configure the HTTP pipeline.
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);
Creates a new instance of the TableClient class.
The URL of the service account that is the target of the desired operation, such as "https://myaccount.table.core.windows.net".
the name of the table
SASCredential used to authenticate requests
Optionaloptions: anyOptional. Options to configure the HTTP pipeline.
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),
);
Creates a new instance of the TableClient class.
The URL of the service account that is the target of the desired operation, such as "https://myaccount.table.core.windows.net".
the name of the table
Azure Active Directory credential used to authenticate requests
Optionaloptions: anyOptional. Options to configure the HTTP pipeline.
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,
);
Creates an instance of TableClient.
A Client string pointing to Azure Storage table service, such as "https://myaccount.table.core.windows.net". You can append a SAS, such as "https://myaccount.table.core.windows.net?sasString".
the name of the table
Optionaloptions: anyOptions to configure the HTTP pipeline.
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,
);
Represents a pipeline for making a HTTP request to a URL. Pipelines can have multiple policies to manage manipulating each request before and after it is made to the server.
ReadonlytableName of the table to perform operations on.
Table Account URL
Insert entity in the table.
The properties for the table entity.
The options parameters.
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);
Creates a table with the tableName passed to the client constructor
The options parameters.
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();
Deletes the specified entity in the table.
The partition key of the entity.
The row key of the entity.
The options parameters.
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>");
Permanently deletes the current table with all of its entities.
The options parameters.
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();
Retrieves details about any stored access policies specified on the table that may be used with Shared Access Signatures.
The options parameters.
Returns a single entity in the table.
The partition key of the entity.
The row key of the entity.
The options parameters.
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}`);
Queries entities in a table.
The options parameters.
Example listing entities
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}`);
}
Sets stored access policies for the table that may be used with Shared Access Signatures.
The Access Control List for the table.
The options parameters.
Submits a Transaction which is composed of a set of actions. You can provide the actions as a list or you can use TableTransaction to help building the transaction.
Example usage:
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);
Example usage with 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);
tuple that contains the action to perform, and the entity to perform the action with
Options for the request.
Update an entity in the table.
The properties of the entity to be updated.
The different modes for updating the entity: - Merge: Updates an entity by updating the entity's properties without replacing the existing entity. - Replace: Updates an existing entity by replacing the entire entity.
The options parameters.
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");
Upsert an entity in the table.
The properties for the table entity.
The different modes for updating the entity: - Merge: Updates an entity by updating the entity's properties without replacing the existing entity. - Replace: Updates an existing entity by replacing the entire entity.
The options parameters.
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");
StaticfromCreates an instance of TableClient from connection string.
Account connection string or a SAS connection string of an Azure storage account.
[ Note - Account connection string can only be used in NODE.JS runtime. ]
Account connection string example -
DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net
SAS connection string example -
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
Optionaloptions: anyOptions to configure the HTTP pipeline.
A new TableClient from the given connection string.
A TableClient represents a Client to the Azure Tables service allowing you to perform operations on a single table.