Bagikan melalui


TableClient class

TableClient mewakili Klien ke layanan Azure Tables yang memungkinkan Anda melakukan operasi pada satu tabel.

Konstruktor

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Membuat instans baru kelas TableClient.

TableClient(string, string, SASCredential, TableServiceClientOptions)

Membuat instans baru kelas TableClient.

TableClient(string, string, TableServiceClientOptions)

Membuat instans TableClient.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

Membuat instans baru kelas TableClient.

Properti

pipeline

Mewakili alur untuk membuat permintaan HTTP ke URL. Alur dapat memiliki beberapa kebijakan untuk mengelola manipulasi setiap permintaan sebelum dan sesudah dibuat ke server.

tableName

Nama tabel untuk melakukan operasi.

url

URL Akun Tabel

Metode

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

Sisipkan entitas dalam tabel.

createTable(OperationOptions)

Membuat tabel dengan tableName yang diteruskan ke konstruktor klien

deleteEntity(string, string, DeleteTableEntityOptions)

Menghapus entitas yang ditentukan dalam tabel.

deleteTable(OperationOptions)

Menghapus tabel saat ini secara permanen dengan semua entitasnya.

fromConnectionString(string, string, TableServiceClientOptions)

Membuat instans TableClient dari string koneksi.

getAccessPolicy(OperationOptions)

Mengambil detail tentang kebijakan akses tersimpan yang ditentukan pada tabel yang dapat digunakan dengan Tanda Tangan Akses Bersama.

getEntity<T>(string, string, GetTableEntityOptions)

Mengembalikan satu entitas dalam tabel.

listEntities<T>(ListTableEntitiesOptions)

Kueri entitas dalam tabel.

setAccessPolicy(SignedIdentifier[], OperationOptions)

Mengatur kebijakan akses tersimpan untuk tabel yang dapat digunakan dengan Tanda Tangan Akses Bersama.

submitTransaction(TransactionAction[], OperationOptions)

Mengirimkan Transaksi yang terdiri dari serangkaian tindakan. Anda dapat memberikan tindakan sebagai daftar atau Anda dapat menggunakan TableTransaction untuk membantu membangun transaksi.

Contoh penggunaan:

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

Contoh penggunaan dengan 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)

Perbarui entitas dalam tabel.

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

Upsert entitas dalam tabel.

Detail Konstruktor

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

Membuat instans baru kelas TableClient.

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

Parameter

url

string

URL akun layanan yang merupakan target operasi yang diinginkan, seperti "https://myaccount.table.core.windows.net".

tableName

string

nama tabel

credential
NamedKeyCredential

NamedKeyCredential digunakan untuk mengautentikasi permintaan. Hanya Didukung untuk Simpul

options
TableServiceClientOptions

Fakultatif. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan nama/kunci akun:

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)

Membuat instans baru kelas TableClient.

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

Parameter

url

string

URL akun layanan yang merupakan target operasi yang diinginkan, seperti "https://myaccount.table.core.windows.net".

tableName

string

nama tabel

credential
SASCredential

SASCredential digunakan untuk mengautentikasi permintaan

options
TableServiceClientOptions

Fakultatif. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan Token SAS:

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)

Membuat instans TableClient.

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

Parameter

url

string

String Klien yang menunjuk ke layanan tabel Azure Storage, seperti "https://myaccount.table.core.windows.net". Anda dapat menambahkan SAS, seperti "https://myaccount.table.core.windows.net?sasString".

tableName

string

nama tabel

options
TableServiceClientOptions

Opsi untuk mengonfigurasi alur HTTP.

Contoh menambahkan token SAS:

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)

Membuat instans baru kelas TableClient.

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

Parameter

url

string

URL akun layanan yang merupakan target operasi yang diinginkan, seperti "https://myaccount.table.core.windows.net".

tableName

string

nama tabel

credential
TokenCredential

Kredensial Azure Active Directory digunakan untuk mengautentikasi permintaan

options
TableServiceClientOptions

Fakultatif. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan kredensial Azure Active Directory:

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

Detail Properti

pipeline

Mewakili alur untuk membuat permintaan HTTP ke URL. Alur dapat memiliki beberapa kebijakan untuk mengelola manipulasi setiap permintaan sebelum dan sesudah dibuat ke server.

pipeline: Pipeline

Nilai Properti

tableName

Nama tabel untuk melakukan operasi.

tableName: string

Nilai Properti

string

url

URL Akun Tabel

url: string

Nilai Properti

string

Detail Metode

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

Sisipkan entitas dalam tabel.

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

Parameter

entity

TableEntity<T>

Properti untuk entitas tabel.

options
OperationOptions

Parameter opsi.

Contoh pembuatan entitas

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

Mengembalikan

createTable(OperationOptions)

Membuat tabel dengan tableName yang diteruskan ke konstruktor klien

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

Parameter

options
OperationOptions

Parameter opsi.

Contoh membuat tabel

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

Mengembalikan

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

Menghapus entitas yang ditentukan dalam tabel.

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

Parameter

partitionKey

string

Kunci partisi entitas.

rowKey

string

Kunci baris entitas.

options
DeleteTableEntityOptions

Parameter opsi.

Contoh menghapus entitas

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

Mengembalikan

deleteTable(OperationOptions)

Menghapus tabel saat ini secara permanen dengan semua entitasnya.

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

Parameter

options
OperationOptions

Parameter opsi.

Contoh menghapus tabel

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

Mengembalikan

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

Membuat instans TableClient dari string koneksi.

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

Parameter

connectionString

string

String koneksi akun atau string koneksi SAS dari akun penyimpanan Azure. [ Catatan - String koneksi akun hanya dapat digunakan dalam runtime NODE.JS. ] Contoh string koneksi akun - contoh string koneksi SAS DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net - 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

Opsi untuk mengonfigurasi alur HTTP.

Mengembalikan

TableClient baru dari string koneksi yang diberikan.

getAccessPolicy(OperationOptions)

Mengambil detail tentang kebijakan akses tersimpan yang ditentukan pada tabel yang dapat digunakan dengan Tanda Tangan Akses Bersama.

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

Parameter

options
OperationOptions

Parameter opsi.

Mengembalikan

getEntity<T>(string, string, GetTableEntityOptions)

Mengembalikan satu entitas dalam tabel.

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

Parameter

partitionKey

string

Kunci partisi entitas.

rowKey

string

Kunci baris entitas.

options
GetTableEntityOptions

Parameter opsi.

Contoh mendapatkan entitas

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

Mengembalikan

listEntities<T>(ListTableEntitiesOptions)

Kueri entitas dalam tabel.

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

Parameter

options
ListTableEntitiesOptions

Parameter opsi.

Contoh entitas daftar

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

Mengembalikan

setAccessPolicy(SignedIdentifier[], OperationOptions)

Mengatur kebijakan akses tersimpan untuk tabel yang dapat digunakan dengan Tanda Tangan Akses Bersama.

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

Parameter

tableAcl

SignedIdentifier[]

Daftar Kontrol Akses untuk tabel.

options
OperationOptions

Parameter opsi.

Mengembalikan

submitTransaction(TransactionAction[], OperationOptions)

Mengirimkan Transaksi yang terdiri dari serangkaian tindakan. Anda dapat memberikan tindakan sebagai daftar atau Anda dapat menggunakan TableTransaction untuk membantu membangun transaksi.

Contoh penggunaan:

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

Contoh penggunaan dengan 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>

Parameter

actions

TransactionAction[]

tuple yang berisi tindakan yang harus dilakukan, dan entitas untuk melakukan tindakan dengan

options
OperationOptions

Opsi untuk permintaan.

Mengembalikan

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

Perbarui entitas dalam tabel.

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

Parameter

entity

TableEntity<T>

Properti entitas yang akan diperbarui.

mode
UpdateMode

Mode yang berbeda untuk memperbarui entitas: - Gabungkan: Memperbarui entitas dengan memperbarui properti entitas tanpa mengganti entitas yang ada. - Ganti: Memperbarui entitas yang ada dengan mengganti seluruh entitas.

options
UpdateTableEntityOptions

Parameter opsi.

Contoh memperbarui entitas

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

Mengembalikan

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

Upsert entitas dalam tabel.

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

Parameter

entity

TableEntity<T>

Properti untuk entitas tabel.

mode
UpdateMode

Mode yang berbeda untuk memperbarui entitas: - Gabungkan: Memperbarui entitas dengan memperbarui properti entitas tanpa mengganti entitas yang ada. - Ganti: Memperbarui entitas yang ada dengan mengganti seluruh entitas.

options
OperationOptions

Parameter opsi.

Contoh upserting entitas

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

Mengembalikan