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

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

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

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

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

Opsional. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan nama/kunci akun:

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)

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

NamedKeyCredential digunakan untuk mengautentikasi permintaan. Hanya Didukung untuk Simpul

options
TableServiceClientOptions

Opsional. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan nama/kunci akun:

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

Membuat instans TableClient.

new TableClient(url: string, tableName: string, 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

options
TableServiceClientOptions

Opsional. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan nama/kunci akun:

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

NamedKeyCredential digunakan untuk mengautentikasi permintaan. Hanya Didukung untuk Simpul

options
TableServiceClientOptions

Opsional. Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan nama/kunci akun:

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

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

Pipeline

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<CreateTableEntityResponse>

Parameter

entity

TableEntity<T>

Properti untuk entitas tabel.

options

OperationOptions

Parameter opsi.

Contoh pembuatan entitas

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

Mengembalikan

createTable(OperationOptions)

Membuat tabel dengan tableName yang diteruskan ke konstruktor klien

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

Parameter

options

OperationOptions

Parameter opsi.

Contoh pembuatan tabel

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

Mengembalikan

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

Menghapus entitas yang ditentukan dalam tabel.

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

Parameter

partitionKey

string

Kunci partisi entitas.

rowKey

string

Kunci baris entitas.

options
DeleteTableEntityOptions

Parameter opsi.

Contoh menghapus entitas

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

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

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

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 -DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net Contoh string koneksi SAS - 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

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

Mengembalikan

listEntities<T>(ListTableEntitiesOptions)

Kueri entitas dalam tabel.

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

Parameter

options
ListTableEntitiesOptions

Parameter opsi.

Contoh entitas daftar

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

Mengembalikan

PagedAsyncIterableIterator<TableEntityResult<T>, TableEntityResultPage<T>>

setAccessPolicy(SignedIdentifier[], OperationOptions)

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

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

Parameter

tableAcl

SignedIdentifier[]

Daftar Access Control untuk tabel.

options

OperationOptions

Parameter opsi.

Mengembalikan

submitTransaction(TransactionAction[])

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

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

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

Parameter

actions

TransactionAction[]

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

Mengembalikan

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

Perbarui entitas dalam tabel.

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

Parameter

entity

TableEntity<T>

Properti entitas yang akan diperbarui.

mode
UpdateMode

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

options
UpdateTableEntityOptions

Parameter opsi.

Contoh memperbarui entitas

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

Mengembalikan

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

Upsert entitas dalam tabel.

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

Parameter

entity

TableEntity<T>

Properti untuk entitas tabel.

mode
UpdateMode

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

options

OperationOptions

Parameter opsi.

Contoh upserting entitas

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

Mengembalikan