TableClient class
Ein TableClient stellt einen Client für den Azure Tables-Dienst dar, mit dem Sie Vorgänge für eine einzelne Tabelle ausführen können.
Konstruktoren
Table |
Erstellt eine neue Instanz der TableClient-Klasse. |
Table |
Erstellt eine neue Instanz der TableClient-Klasse. |
Table |
Erstellt eine Instanz von TableClient. |
Table |
Erstellt eine neue Instanz der TableClient-Klasse. |
Eigenschaften
pipeline | Stellt eine Pipeline zum Erstellen einer HTTP-Anforderung an eine URL dar. Pipelines können über mehrere Richtlinien verfügen, um die Bearbeitung jeder Anforderung vor und nach dem Ausführen an den Server zu verwalten. |
table |
Der Name der Tabelle, für die Vorgänge ausgeführt werden sollen. |
url | Tabellenkonto-URL |
Methoden
create |
Fügen Sie die Entität in die Tabelle ein. |
create |
Erstellt eine Tabelle mit dem an den Clientkonstruktor übergebenen TableName |
delete |
Löscht die angegebene Entität in der Tabelle. |
delete |
Löscht die aktuelle Tabelle dauerhaft mit allen zugehörigen Entitäten. |
from |
Erstellt eine Instanz von TableClient aus verbindungszeichenfolge. |
get |
Ruft Details zu allen gespeicherten Zugriffsrichtlinien ab, die in der Tabelle angegeben sind, die mit Freigegebenen Zugriffssignaturen verwendet werden können. |
get |
Gibt eine einzelne Entität in der Tabelle zurück. |
list |
Fragt Entitäten in einer Tabelle ab. |
set |
Legt gespeicherte Zugriffsrichtlinien für die Tabelle fest, die mit Signaturen für den freigegebenen Zugriff verwendet werden kann. |
submit |
Sendet eine Transaktion, die aus einer Gruppe von Aktionen besteht. Sie können die Aktionen als Liste bereitstellen oder TableTransaction- verwenden, um die Transaktion zu erstellen. Beispielverwendung:
Beispielverwendung mit TableTransaction:
|
update |
Aktualisieren sie eine Entität in der Tabelle. |
upsert |
Upsert eine Entität in der Tabelle. |
Details zum Konstruktor
TableClient(string, string, NamedKeyCredential, TableServiceClientOptions)
Erstellt eine neue Instanz der TableClient-Klasse.
new TableClient(url: string, tableName: string, credential: NamedKeyCredential, options?: TableServiceClientOptions)
Parameter
- url
-
string
Die URL des Dienstkontos, das das Ziel des gewünschten Vorgangs ist, z. B. "https://myaccount.table.core.windows.net".
- tableName
-
string
der Name der Tabelle
- credential
- NamedKeyCredential
NamedKeyCredential, die zum Authentifizieren von Anforderungen verwendet wird. Nur für Knoten unterstützt
- options
- TableServiceClientOptions
Wahlfrei. Optionen zum Konfigurieren der HTTP-Pipeline.
Beispiel für die Verwendung eines Kontonamens/Schlüssels:
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)
Erstellt eine neue Instanz der TableClient-Klasse.
new TableClient(url: string, tableName: string, credential: SASCredential, options?: TableServiceClientOptions)
Parameter
- url
-
string
Die URL des Dienstkontos, das das Ziel des gewünschten Vorgangs ist, z. B. "https://myaccount.table.core.windows.net".
- tableName
-
string
der Name der Tabelle
- credential
- SASCredential
SASCredential für die Authentifizierung von Anforderungen
- options
- TableServiceClientOptions
Wahlfrei. Optionen zum Konfigurieren der HTTP-Pipeline.
Beispiel für die Verwendung eines SAS-Tokens:
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)
Erstellt eine Instanz von TableClient.
new TableClient(url: string, tableName: string, options?: TableServiceClientOptions)
Parameter
- url
-
string
Eine Clientzeichenfolge, die auf den Azure Storage-Tabellendienst verweist, z. B. "https://myaccount.table.core.windows.net". Sie können eine SAS anfügen, z. B. "https://myaccount.table.core.windows.net?sasString".
- tableName
-
string
der Name der Tabelle
- options
- TableServiceClientOptions
Optionen zum Konfigurieren der HTTP-Pipeline.
Beispiel zum Anfügen eines SAS-Tokens:
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)
Erstellt eine neue Instanz der TableClient-Klasse.
new TableClient(url: string, tableName: string, credential: TokenCredential, options?: TableServiceClientOptions)
Parameter
- url
-
string
Die URL des Dienstkontos, das das Ziel des gewünschten Vorgangs ist, z. B. "https://myaccount.table.core.windows.net".
- tableName
-
string
der Name der Tabelle
- credential
- TokenCredential
Azure Active Directory-Anmeldeinformationen zum Authentifizieren von Anforderungen
- options
- TableServiceClientOptions
Wahlfrei. Optionen zum Konfigurieren der HTTP-Pipeline.
Beispiel für die Verwendung von Azure Active Directory-Anmeldeinformationen:
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
);
Details zur Eigenschaft
pipeline
Stellt eine Pipeline zum Erstellen einer HTTP-Anforderung an eine URL dar. Pipelines können über mehrere Richtlinien verfügen, um die Bearbeitung jeder Anforderung vor und nach dem Ausführen an den Server zu verwalten.
pipeline: Pipeline
Eigenschaftswert
tableName
Der Name der Tabelle, für die Vorgänge ausgeführt werden sollen.
tableName: string
Eigenschaftswert
string
url
Tabellenkonto-URL
url: string
Eigenschaftswert
string
Details zur Methode
createEntity<T>(TableEntity<T>, OperationOptions)
Fügen Sie die Entität in die Tabelle ein.
function createEntity<T>(entity: TableEntity<T>, options?: OperationOptions): Promise<TableInsertEntityHeaders>
Parameter
- entity
-
TableEntity<T>
Die Eigenschaften für die Tabellenentität.
- options
- OperationOptions
Die Optionsparameter.
Beispiel zum Erstellen einer Entität
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!"});
Gibt zurück
Promise<TableInsertEntityHeaders>
createTable(OperationOptions)
Erstellt eine Tabelle mit dem an den Clientkonstruktor übergebenen TableName
function createTable(options?: OperationOptions): Promise<void>
Parameter
- options
- OperationOptions
Die Optionsparameter.
Beispiel zum Erstellen einer Tabelle
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();
Gibt zurück
Promise<void>
deleteEntity(string, string, DeleteTableEntityOptions)
Löscht die angegebene Entität in der Tabelle.
function deleteEntity(partitionKey: string, rowKey: string, options?: DeleteTableEntityOptions): Promise<TableDeleteEntityHeaders>
Parameter
- partitionKey
-
string
Der Partitionsschlüssel der Entität.
- rowKey
-
string
Der Zeilenschlüssel der Entität.
- options
- DeleteTableEntityOptions
Die Optionsparameter.
Beispiel zum Löschen einer Entität
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>")
Gibt zurück
Promise<TableDeleteEntityHeaders>
deleteTable(OperationOptions)
Löscht die aktuelle Tabelle dauerhaft mit allen zugehörigen Entitäten.
function deleteTable(options?: OperationOptions): Promise<void>
Parameter
- options
- OperationOptions
Die Optionsparameter.
Beispiel zum Löschen einer Tabelle
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();
Gibt zurück
Promise<void>
fromConnectionString(string, string, TableServiceClientOptions)
Erstellt eine Instanz von TableClient aus verbindungszeichenfolge.
static function fromConnectionString(connectionString: string, tableName: string, options?: TableServiceClientOptions): TableClient
Parameter
- connectionString
-
string
Kontoverbindungszeichenfolge oder SAS-Verbindungszeichenfolge eines Azure-Speicherkontos.
[ Hinweis : Kontoverbindungszeichenfolge kann nur in NODE.JS Laufzeit verwendet werden. ] Beispiel für kontoverbindungszeichenfolge - beispiel für DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net
SAS-Verbindungszeichenfolge - 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
Optionen zum Konfigurieren der HTTP-Pipeline.
Gibt zurück
Ein neuer TableClient aus der angegebenen Verbindungszeichenfolge.
getAccessPolicy(OperationOptions)
Ruft Details zu allen gespeicherten Zugriffsrichtlinien ab, die in der Tabelle angegeben sind, die mit Freigegebenen Zugriffssignaturen verwendet werden können.
function getAccessPolicy(options?: OperationOptions): Promise<GetAccessPolicyResponse>
Parameter
- options
- OperationOptions
Die Optionsparameter.
Gibt zurück
Promise<GetAccessPolicyResponse>
getEntity<T>(string, string, GetTableEntityOptions)
Gibt eine einzelne Entität in der Tabelle zurück.
function getEntity<T>(partitionKey: string, rowKey: string, options?: GetTableEntityOptions): Promise<GetTableEntityResponse<TableEntityResult<T>>>
Parameter
- partitionKey
-
string
Der Partitionsschlüssel der Entität.
- rowKey
-
string
Der Zeilenschlüssel der Entität.
- options
- GetTableEntityOptions
Die Optionsparameter.
Beispiel für das Abrufen einer Entität
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);
Gibt zurück
Promise<GetTableEntityResponse<TableEntityResult<T>>>
listEntities<T>(ListTableEntitiesOptions)
Fragt Entitäten in einer Tabelle ab.
function listEntities<T>(options?: ListTableEntitiesOptions): PagedAsyncIterableIterator<TableEntityResult<T>, TableEntityResultPage<T>, PageSettings>
Parameter
- options
- ListTableEntitiesOptions
Die Optionsparameter.
Beispiel zum Auflisten von Entitäten
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);
}
Gibt zurück
setAccessPolicy(SignedIdentifier[], OperationOptions)
Legt gespeicherte Zugriffsrichtlinien für die Tabelle fest, die mit Signaturen für den freigegebenen Zugriff verwendet werden kann.
function setAccessPolicy(tableAcl: SignedIdentifier[], options?: OperationOptions): Promise<TableSetAccessPolicyHeaders>
Parameter
- tableAcl
Die Zugriffssteuerungsliste für die Tabelle.
- options
- OperationOptions
Die Optionsparameter.
Gibt zurück
Promise<TableSetAccessPolicyHeaders>
submitTransaction(TransactionAction[])
Sendet eine Transaktion, die aus einer Gruppe von Aktionen besteht. Sie können die Aktionen als Liste bereitstellen oder TableTransaction- verwenden, um die Transaktion zu erstellen.
Beispielverwendung:
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);
Beispielverwendung mit 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
Tupel, das die auszuführende Aktion enthält, und die Entität zum Ausführen der Aktion mit
Gibt zurück
Promise<TableTransactionResponse>
updateEntity<T>(TableEntity<T>, UpdateMode, UpdateTableEntityOptions)
Aktualisieren sie eine Entität in der Tabelle.
function updateEntity<T>(entity: TableEntity<T>, mode?: UpdateMode, options?: UpdateTableEntityOptions): Promise<TableUpdateEntityHeaders>
Parameter
- entity
-
TableEntity<T>
Die Eigenschaften der Entität, die aktualisiert werden soll.
- mode
- UpdateMode
Die verschiedenen Modi zum Aktualisieren der Entität: - Zusammenführen: Aktualisiert eine Entität, indem die Eigenschaften der Entität aktualisiert werden, ohne die vorhandene Entität zu ersetzen. - Ersetzen: Aktualisiert eine vorhandene Entität, indem die gesamte Entität ersetzt wird.
- options
- UpdateTableEntityOptions
Die Optionsparameter.
Beispiel für die Aktualisierung einer Entität
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")
Gibt zurück
Promise<TableUpdateEntityHeaders>
upsertEntity<T>(TableEntity<T>, UpdateMode, OperationOptions)
Upsert eine Entität in der Tabelle.
function upsertEntity<T>(entity: TableEntity<T>, mode?: UpdateMode, options?: OperationOptions): Promise<TableMergeEntityHeaders>
Parameter
- entity
-
TableEntity<T>
Die Eigenschaften für die Tabellenentität.
- mode
- UpdateMode
Die verschiedenen Modi zum Aktualisieren der Entität: - Zusammenführen: Aktualisiert eine Entität, indem die Eigenschaften der Entität aktualisiert werden, ohne die vorhandene Entität zu ersetzen. - Ersetzen: Aktualisiert eine vorhandene Entität, indem die gesamte Entität ersetzt wird.
- options
- OperationOptions
Die Optionsparameter.
Beispiel zum Upserting einer Entität
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")
Gibt zurück
Promise<TableMergeEntityHeaders>