مشاركة عبر


TableClient class

يمثل TableClient عميلا لخدمة Azure Tables مما يسمح لك بتنفيذ العمليات على جدول واحد.

المنشئون

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

إنشاء مثيل جديد لفئة TableClient.

TableClient(string, string, SASCredential, TableServiceClientOptions)

إنشاء مثيل جديد لفئة TableClient.

TableClient(string, string, TableServiceClientOptions)

إنشاء مثيل TableClient.

TableClient(string, string, TokenCredential, TableServiceClientOptions)

إنشاء مثيل جديد لفئة TableClient.

الخصائص

pipeline

يمثل مسارا لإجراء طلب HTTP إلى عنوان URL. يمكن أن يكون للبنية الأساسية لبرنامج ربط العمليات التجارية نهج متعددة لإدارة معالجة كل طلب قبل وبعد تقديمه إلى الخادم.

tableName

اسم الجدول الذي تريد تنفيذ العمليات عليه.

url

عنوان URL لحساب الجدول

الأساليب

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

إدراج كيان في الجدول.

createTable(OperationOptions)

إنشاء جدول باستخدام tableName الذي تم تمريره إلى الدالة الإنشائية للعميل

deleteEntity(string, string, DeleteTableEntityOptions)

حذف الكيان المحدد في الجدول.

deleteTable(OperationOptions)

حذف الجدول الحالي بشكل دائم مع جميع الكيانات الخاصة به.

fromConnectionString(string, string, TableServiceClientOptions)

إنشاء مثيل TableClient من سلسلة الاتصال.

getAccessPolicy(OperationOptions)

استرداد تفاصيل حول أي نهج وصول مخزنة محددة في الجدول والتي يمكن استخدامها مع توقيعات الوصول المشترك.

getEntity<T>(string, string, GetTableEntityOptions)

إرجاع كيان واحد في الجدول.

listEntities<T>(ListTableEntitiesOptions)

الاستعلام عن الكيانات في جدول.

setAccessPolicy(SignedIdentifier[], OperationOptions)

تعيين نهج الوصول المخزنة للجدول الذي يمكن استخدامه مع توقيعات الوصول المشترك.

submitTransaction(TransactionAction[])

إرسال معاملة تتكون من مجموعة من الإجراءات. يمكنك توفير الإجراءات كقوائم أو يمكنك استخدام TableTransaction للمساعدة في إنشاء المعاملة.

مثال على الاستخدام:

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

مثال على الاستخدام مع 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)

تحديث كيان في الجدول.

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

رفع كيان في الجدول.

تفاصيل المنشئ

TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)

إنشاء مثيل جديد لفئة TableClient.

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

المعلمات

url

string

عنوان URL لحساب الخدمة الذي هو الهدف من العملية المطلوبة، مثل "https://myaccount.table.core.windows.net".

tableName

string

اسم الجدول

credential
NamedKeyCredential

يستخدم NamedKeyCredential لمصادقة الطلبات. معتمد فقط للعقدة

options
TableServiceClientOptions

اختياري. خيارات لتكوين البنية الأساسية لبرنامج ربط العمليات التجارية HTTP.

مثال على استخدام اسم/مفتاح حساب:

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)

إنشاء مثيل جديد لفئة TableClient.

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

المعلمات

url

string

عنوان URL لحساب الخدمة الذي هو الهدف من العملية المطلوبة، مثل "https://myaccount.table.core.windows.net".

tableName

string

اسم الجدول

credential
SASCredential

SASCredential المستخدم لمصادقة الطلبات

options
TableServiceClientOptions

اختياري. خيارات لتكوين البنية الأساسية لبرنامج ربط العمليات التجارية HTTP.

مثال باستخدام رمز 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)

إنشاء مثيل TableClient.

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

المعلمات

url

string

سلسلة عميل تشير إلى خدمة جدول تخزين Azure، مثل "https://myaccount.table.core.windows.net". يمكنك إلحاق SAS، مثل "https://myaccount.table.core.windows.net?sasString".

tableName

string

اسم الجدول

options
TableServiceClientOptions

خيارات لتكوين البنية الأساسية لبرنامج ربط العمليات التجارية HTTP.

مثال إلحاق رمز 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)

إنشاء مثيل جديد لفئة TableClient.

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

المعلمات

url

string

عنوان URL لحساب الخدمة الذي هو الهدف من العملية المطلوبة، مثل "https://myaccount.table.core.windows.net".

tableName

string

اسم الجدول

credential
TokenCredential

بيانات اعتماد Azure Active Directory المستخدمة لمصادقة الطلبات

options
TableServiceClientOptions

اختياري. خيارات لتكوين البنية الأساسية لبرنامج ربط العمليات التجارية HTTP.

مثال باستخدام بيانات اعتماد 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
);

تفاصيل الخاصية

pipeline

يمثل مسارا لإجراء طلب HTTP إلى عنوان URL. يمكن أن يكون للبنية الأساسية لبرنامج ربط العمليات التجارية نهج متعددة لإدارة معالجة كل طلب قبل وبعد تقديمه إلى الخادم.

pipeline: Pipeline

قيمة الخاصية

tableName

اسم الجدول الذي تريد تنفيذ العمليات عليه.

tableName: string

قيمة الخاصية

string

url

عنوان URL لحساب الجدول

url: string

قيمة الخاصية

string

تفاصيل الأسلوب

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

إدراج كيان في الجدول.

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

المعلمات

entity

TableEntity<T>

خصائص كيان الجدول.

options
OperationOptions

معلمات الخيارات.

مثال على إنشاء كيان

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

المرتجعات

createTable(OperationOptions)

إنشاء جدول باستخدام tableName الذي تم تمريره إلى الدالة الإنشائية للعميل

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

المعلمات

options
OperationOptions

معلمات الخيارات.

مثال على إنشاء جدول

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

المرتجعات

Promise<void>

deleteEntity(string, string, DeleteTableEntityOptions)

حذف الكيان المحدد في الجدول.

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

المعلمات

partitionKey

string

مفتاح القسم للكيان.

rowKey

string

مفتاح الصف للكيان.

options
DeleteTableEntityOptions

معلمات الخيارات.

مثال على حذف كيان

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

المرتجعات

deleteTable(OperationOptions)

حذف الجدول الحالي بشكل دائم مع جميع الكيانات الخاصة به.

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

المعلمات

options
OperationOptions

معلمات الخيارات.

مثال على حذف جدول

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

المرتجعات

Promise<void>

fromConnectionString(string, string, TableServiceClientOptions)

إنشاء مثيل TableClient من سلسلة الاتصال.

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

المعلمات

connectionString

string

سلسلة اتصال الحساب أو سلسلة اتصال SAS لحساب تخزين Azure. [ ملاحظة - يمكن استخدام سلسلة اتصال الحساب فقط في وقت تشغيل NODE.JS. ] مثال سلسلة اتصال الحساب - DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net مثال سلسلة اتصال 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

خيارات لتكوين البنية الأساسية لبرنامج ربط العمليات التجارية HTTP.

المرتجعات

TableClient جديد من سلسلة الاتصال المحددة.

getAccessPolicy(OperationOptions)

استرداد تفاصيل حول أي نهج وصول مخزنة محددة في الجدول والتي يمكن استخدامها مع توقيعات الوصول المشترك.

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

المعلمات

options
OperationOptions

معلمات الخيارات.

المرتجعات

getEntity<T>(string, string, GetTableEntityOptions)

إرجاع كيان واحد في الجدول.

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

المعلمات

partitionKey

string

مفتاح القسم للكيان.

rowKey

string

مفتاح الصف للكيان.

options
GetTableEntityOptions

معلمات الخيارات.

مثال على الحصول على كيان

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

المرتجعات

listEntities<T>(ListTableEntitiesOptions)

الاستعلام عن الكيانات في جدول.

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

المعلمات

options
ListTableEntitiesOptions

معلمات الخيارات.

مثال على سرد الكيانات

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

المرتجعات

setAccessPolicy(SignedIdentifier[], OperationOptions)

تعيين نهج الوصول المخزنة للجدول الذي يمكن استخدامه مع توقيعات الوصول المشترك.

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

المعلمات

tableAcl

SignedIdentifier[]

قائمة التحكم بالوصول للجدول.

options
OperationOptions

معلمات الخيارات.

المرتجعات

submitTransaction(TransactionAction[])

إرسال معاملة تتكون من مجموعة من الإجراءات. يمكنك توفير الإجراءات كقوائم أو يمكنك استخدام TableTransaction للمساعدة في إنشاء المعاملة.

مثال على الاستخدام:

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

مثال على الاستخدام مع 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>

المعلمات

actions

TransactionAction[]

المجموعة التي تحتوي على الإجراء المطلوب تنفيذه، والكيان الذي يجب تنفيذ الإجراء به

المرتجعات

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

تحديث كيان في الجدول.

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

المعلمات

entity

TableEntity<T>

خصائص الكيان الذي سيتم تحديثه.

mode
UpdateMode

الأوضاع المختلفة لتحديث الكيان: - الدمج: تحديث كيان عن طريق تحديث خصائص الكيان دون استبدال الكيان الموجود. - استبدال: تحديث كيان موجود عن طريق استبدال الكيان بأكمله.

options
UpdateTableEntityOptions

معلمات الخيارات.

مثال على تحديث كيان

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

المرتجعات

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

رفع كيان في الجدول.

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

المعلمات

entity

TableEntity<T>

خصائص كيان الجدول.

mode
UpdateMode

الأوضاع المختلفة لتحديث الكيان: - الدمج: تحديث كيان عن طريق تحديث خصائص الكيان دون استبدال الكيان الموجود. - استبدال: تحديث كيان موجود عن طريق استبدال الكيان بأكمله.

options
OperationOptions

معلمات الخيارات.

مثال على رفع قيمة كيان

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

المرتجعات