Package version:

A TableClient represents a Client to the Azure Tables service allowing you to perform operations on a single table.

Constructors

  • Creates a new instance of the TableClient class.

    Parameters

    • url: string

      The URL of the service account that is the target of the desired operation, such as "https://myaccount.table.core.windows.net".

    • tableName: string

      the name of the table

    • credential: NamedKeyCredential

      NamedKeyCredential used to authenticate requests. Only Supported for Node

    • Optionaloptions: any

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

    Returns TableClient

  • Creates a new instance of the TableClient class.

    Parameters

    • url: string

      The URL of the service account that is the target of the desired operation, such as "https://myaccount.table.core.windows.net".

    • tableName: string

      the name of the table

    • credential: SASCredential

      SASCredential used to authenticate requests

    • Optionaloptions: any

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

    Returns TableClient

  • Creates a new instance of the TableClient class.

    Parameters

    • url: string

      The URL of the service account that is the target of the desired operation, such as "https://myaccount.table.core.windows.net".

    • tableName: string

      the name of the table

    • credential: TokenCredential

      Azure Active Directory credential used to authenticate requests

    • Optionaloptions: any

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

    Returns TableClient

  • Creates an instance of TableClient.

    Parameters

    • url: string

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

    • tableName: string

      the name of the table

    • Optionaloptions: any

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

    Returns TableClient

Properties

pipeline: Pipeline

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.

tableName: string

Name of the table to perform operations on.

url: string

Table Account URL

Methods

  • Insert entity in the table.

    Type Parameters

    • T extends object

    Parameters

    • entity: TableEntity<T>

      The properties for the table entity.

    • options: OperationOptions = {}

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

    Returns Promise<TableInsertEntityHeaders>

  • Creates a table with the tableName passed to the client constructor

    Parameters

    • options: OperationOptions = {}

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

    Returns Promise<void>

  • Deletes the specified entity in the table.

    Parameters

    • partitionKey: string

      The partition key of the entity.

    • rowKey: string

      The row key of the entity.

    • options: any = {}

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

    Returns Promise<TableDeleteEntityHeaders>

  • Permanently deletes the current table with all of its entities.

    Parameters

    • options: OperationOptions = {}

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

    Returns Promise<void>

  • Returns a single entity in the table.

    Type Parameters

    • T extends object = Record<string, unknown>

    Parameters

    • partitionKey: string

      The partition key of the entity.

    • rowKey: string

      The row key of the entity.

    • options: any = {}

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

    Returns Promise<GetTableEntityResponse<TableEntityResult<T>>>

  • Queries entities in a table.

    Type Parameters

    • T extends object = Record<string, unknown>

    Parameters

    • options: any = {}

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

    Returns PagedAsyncIterableIterator<TableEntityResult<T>, any>

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

    Parameters

    • actions: {}

      tuple that contains the action to perform, and the entity to perform the action with

      • options: OperationOptions = {}

        Options for the request.

      Returns Promise<TableTransactionResponse>

    • Update an entity in the table.

      Type Parameters

      • T extends object

      Parameters

      • entity: TableEntity<T>

        The properties of the entity to be updated.

      • mode: UpdateMode = "Merge"

        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.

      • options: any = {}

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

      Returns Promise<TableUpdateEntityHeaders>

    • Upsert an entity in the table.

      Type Parameters

      • T extends object

      Parameters

      • entity: TableEntity<T>

        The properties for the table entity.

      • mode: UpdateMode = "Merge"

        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.

      • options: OperationOptions = {}

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

      Returns Promise<TableMergeEntityHeaders>

    • Creates an instance of TableClient from connection string.

      Parameters

      • connectionString: 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

      • tableName: string
      • Optionaloptions: any

        Options to configure the HTTP pipeline.

      Returns TableClient

      A new TableClient from the given connection string.