-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post release automated changes for tables releases (#18663)
Post release automated changes for azure-data-tables
- Loading branch information
Showing
35 changed files
with
2,332 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
page_type: sample | ||
languages: | ||
- javascript | ||
products: | ||
- azure | ||
- azure-table-storage | ||
urlFragment: data-tables-javascript | ||
--- | ||
|
||
# Azure Data Tables client library samples for JavaScript | ||
|
||
These sample programs show how to use the JavaScript client libraries for Azure Data Tables in some common scenarios. | ||
|
||
| **File Name** | **Description** | | ||
| ----------------------------------------------------- | ------------------------------------------------------------------------- | | ||
| [workingWithBigInt.js][workingwithbigint] | creates and works with an entity containing a bigint | | ||
| [workingWithInt64.js][workingwithint64] | creates and works with an entity containing an Int64 value | | ||
| [transactionWithHelper.js][transactionwithhelper] | sends transactional request using TableTransaction helper | | ||
| [transactionOperations.js][transactionoperations] | sends transactional batch requests | | ||
| [usingContinuationToken.js][usingcontinuationtoken] | queries entities in a table by page manually handling continuation tokens | | ||
| [authenticationMethods.js][authenticationmethods] | authenticates using different authentication methods | | ||
| [createAndDeleteEntities.js][createanddeleteentities] | creates and deletes a entities in a table | | ||
| [createAndDeleteTable.js][createanddeletetable] | creates and deletes a table | | ||
| [generateTableSAS.js][generatetablesas] | generate a Table Account SAS token | | ||
| [queryEntities.js][queryentities] | queries entities in a table | | ||
| [queryTables.js][querytables] | queries tables | | ||
| [updateAndUpsertEntities.js][updateandupsertentities] | updates and upserts entities in a table | | ||
|
||
## Prerequisites | ||
|
||
The sample programs are compatible with [LTS versions of Node.js](https://nodejs.org/about/releases/). | ||
|
||
You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: | ||
|
||
- [Azure Storage instance][createinstance_azurestorageinstance] | ||
|
||
Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. | ||
|
||
Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. | ||
|
||
## Setup | ||
|
||
To run the samples using the published version of the package: | ||
|
||
1. Install the dependencies using `npm`: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. | ||
|
||
3. Run whichever samples you like (note that some samples may require additional setup, see the table above): | ||
|
||
```bash | ||
node workingWithBigInt.js | ||
``` | ||
|
||
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): | ||
|
||
```bash | ||
npx cross-env TABLES_URL="<tables url>" ACCOUNT_NAME="<account name>" ACCOUNT_KEY="<account key>" node workingWithBigInt.js | ||
``` | ||
|
||
## Next Steps | ||
|
||
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. | ||
|
||
[workingwithbigint]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/workingWithBigInt.js | ||
[workingwithint64]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/workingWithInt64.js | ||
[transactionwithhelper]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/transactionWithHelper.js | ||
[transactionoperations]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/transactionOperations.js | ||
[usingcontinuationtoken]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/usingContinuationToken.js | ||
[authenticationmethods]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/authenticationMethods.js | ||
[createanddeleteentities]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/createAndDeleteEntities.js | ||
[createanddeletetable]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/createAndDeleteTable.js | ||
[generatetablesas]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/generateTableSAS.js | ||
[queryentities]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/queryEntities.js | ||
[querytables]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/queryTables.js | ||
[updateandupsertentities]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/tables/data-tables/samples/v13/javascript/updateAndUpsertEntities.js | ||
[apiref]: https://docs.microsoft.com/javascript/api/@azure/data-tables | ||
[freesub]: https://azure.microsoft.com/free/ | ||
[createinstance_azurestorageinstance]: https://docs.microsoft.com/azure/storage/tables/table-storage-quickstart-portal | ||
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/tables/data-tables/README.md |
111 changes: 111 additions & 0 deletions
111
sdk/tables/data-tables/samples/v13/javascript/authenticationMethods.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* This sample demonstrates how to use the different methods of authentication | ||
* to make calls to the Azure Tables Service | ||
* | ||
* @summary authenticates using different authentication methods | ||
*/ | ||
const { | ||
TableServiceClient, | ||
AzureNamedKeyCredential, | ||
AzureSASCredential | ||
} = require("@azure/data-tables"); | ||
|
||
const { DefaultAzureCredential } = require("@azure/identity"); | ||
|
||
// Load the .env file if it exists | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
// URL of the tables endpoint | ||
const tablesUrl = process.env["TABLES_URL"] || ""; | ||
|
||
// You can find your storage account's name, connection strings and keys in the Azure portal. | ||
// Navigate to Settings > Access keys in your storage account's menu blade to see connection strings for both primary and secondary access keys | ||
const accountConnectionString = process.env["ACCOUNT_CONNECTION_STRING"] || ""; | ||
const accountName = process.env["ACCOUNT_NAME"] || ""; | ||
const accountKey = process.env["ACCOUNT_KEY"] || ""; | ||
|
||
// You can generate a SAS connection string and token for your storage account in the Azure Portal | ||
// Navigate to Settings > "Shared access signature" in your storage account's menu blade select the Allowed services, resource types, permissions and expiry options | ||
// and generate your SAS and connection string. | ||
const sasConnectionString = process.env["SAS_CONNECTION_STRING"] || ""; | ||
const sasToken = process.env["SAS_TOKEN"] || ""; | ||
|
||
/** | ||
* Create a TableServiceCLient using a SAS connection String | ||
*/ | ||
async function tableServiceClientWithSasConnectionString() { | ||
const client = TableServiceClient.fromConnectionString(sasConnectionString); | ||
countTablesWithClient(client); | ||
} | ||
|
||
/** | ||
* Create a TableServiceCLient using a SAS connection String | ||
*/ | ||
async function tableServiceClientWithAAD() { | ||
// DefaultAzureCredential expects the following three environment variables: | ||
// - AZURE_TENANT_ID: The tenant ID in Azure Active Directory | ||
// - AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant | ||
// - AZURE_CLIENT_SECRET: The client secret for the registered application | ||
const credential = new DefaultAzureCredential(); | ||
const client = new TableServiceClient(tablesUrl, credential); | ||
countTablesWithClient(client); | ||
} | ||
|
||
/** | ||
* Create a TableServiceCLient using a SAS token | ||
*/ | ||
async function tableServiceClientWithSasToken() { | ||
const client = new TableServiceClient(tablesUrl, new AzureSASCredential(sasToken)); | ||
countTablesWithClient(client); | ||
} | ||
|
||
/** | ||
* Create a TableServiceCLient using an Account connection String. | ||
* Note that this authentication method is only supported in Node, | ||
* and it is not available for browsers | ||
*/ | ||
async function tableServiceClientWithAccountConnectionString() { | ||
const client = TableServiceClient.fromConnectionString(accountConnectionString); | ||
countTablesWithClient(client); | ||
} | ||
|
||
/** | ||
* Create a TableServiceCLient using account name and account key | ||
* Note that this authentication method is only supported in Node, | ||
* and it is not available for browsers | ||
*/ | ||
async function tableServiceClientWithAccountKey() { | ||
const creds = new AzureNamedKeyCredential(accountName, accountKey); | ||
const client = new TableServiceClient(tablesUrl, creds); | ||
countTablesWithClient(client); | ||
} | ||
|
||
async function countTablesWithClient(client) { | ||
const tablesIterator = client.listTables(); | ||
let count = 0; | ||
for await (const _table of tablesIterator) { | ||
count++; | ||
} | ||
|
||
console.log(`Listed ${count} tables`); | ||
} | ||
|
||
async function main() { | ||
console.log("== Client Authentication Methods Sample =="); | ||
|
||
await tableServiceClientWithSasConnectionString(); | ||
await tableServiceClientWithSasToken(); | ||
|
||
await tableServiceClientWithAccountConnectionString(); | ||
await tableServiceClientWithAccountKey(); | ||
|
||
await tableServiceClientWithAAD(); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); |
105 changes: 105 additions & 0 deletions
105
sdk/tables/data-tables/samples/v13/javascript/createAndDeleteEntities.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* This sample demonstrates create and delete entities in a table | ||
* | ||
* @summary creates and deletes a entities in a table | ||
*/ | ||
|
||
const { TableClient, AzureNamedKeyCredential } = require("@azure/data-tables"); | ||
|
||
// Load the .env file if it exists | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
const tablesUrl = process.env["TABLES_URL"] || ""; | ||
const accountName = process.env["ACCOUNT_NAME"] || ""; | ||
const accountKey = process.env["ACCOUNT_KEY"] || ""; | ||
|
||
async function createSimpleDateEntity() { | ||
// Note that this sample assumes that a table with tableName exists | ||
const tableName = `createSimpleDateEntityTable`; | ||
|
||
// See authenticationMethods sample for other options of creating a new client | ||
const creds = new AzureNamedKeyCredential(accountName, accountKey); | ||
const client = new TableClient(tablesUrl, tableName, creds); | ||
|
||
await client.createTable(); | ||
|
||
const entity = { | ||
partitionKey: "p1", | ||
rowKey: "r1", | ||
date: new Date() | ||
}; | ||
|
||
await client.createEntity(entity); | ||
|
||
await client.deleteTable(); | ||
} | ||
|
||
async function createComplexDateEntity() { | ||
// Note that this sample assumes that a table with tableName exists | ||
const tableName = `createComplexDateEntityTable`; | ||
|
||
// See authenticationMethods sample for other options of creating a new client | ||
const creds = new AzureNamedKeyCredential(accountName, accountKey); | ||
const client = new TableClient(tablesUrl, tableName, creds); | ||
|
||
await client.createTable(); | ||
|
||
// For higher precision dates we need to pass the | ||
const date = { type: "DateTime", value: "2016-06-10T21:42:24.7607389" }; | ||
|
||
const entity = { | ||
partitionKey: "p2", | ||
rowKey: "r2", | ||
date | ||
}; | ||
|
||
await client.createEntity(entity); | ||
|
||
await client.deleteTable(); | ||
} | ||
|
||
async function createAndDeleteEntities() { | ||
console.log("== Create and delete entities Sample =="); | ||
|
||
// Note that this sample assumes that a table with tableName exists | ||
const tableName = `createAndDeleteEntitiesTable`; | ||
|
||
// See authenticationMethods sample for other options of creating a new client | ||
const creds = new AzureNamedKeyCredential(accountName, accountKey); | ||
const client = new TableClient(tablesUrl, tableName, creds); | ||
|
||
// Create the table | ||
await client.createTable(); | ||
|
||
const entity = { | ||
partitionKey: "Stationery", | ||
rowKey: "A1", | ||
name: "Marker Set", | ||
price: 5.0, | ||
quantity: 21 | ||
}; | ||
|
||
// Create the new entity | ||
await client.createEntity(entity); | ||
|
||
// Delete the entity | ||
await client.deleteEntity(entity.partitionKey, entity.rowKey); | ||
|
||
// Delete the table for cleanup | ||
// Create the table | ||
await client.deleteTable(); | ||
} | ||
|
||
async function main() { | ||
await createAndDeleteEntities(); | ||
await createSimpleDateEntity(); | ||
await createComplexDateEntity(); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); |
56 changes: 56 additions & 0 deletions
56
sdk/tables/data-tables/samples/v13/javascript/createAndDeleteTable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* This sample demonstrates create and delete a table | ||
* | ||
* @summary creates and deletes a table | ||
*/ | ||
|
||
const { TableServiceClient, TableClient } = require("@azure/data-tables"); | ||
const { v4 } = require("uuid"); | ||
|
||
// Load the .env file if it exists | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
const sasConnectionString = process.env["SAS_CONNECTION_STRING"] || ""; | ||
const tableSufix = v4().replace(/-/g, ""); | ||
|
||
async function createAndDeleteTable() { | ||
console.log("== Delete and create table Sample =="); | ||
|
||
// See authenticationMethods sample for other options of creating a new client | ||
const serviceClient = TableServiceClient.fromConnectionString(sasConnectionString); | ||
|
||
// Create a new table | ||
const tableName = `SampleCreateAndDeleteTable${tableSufix}`; | ||
await serviceClient.createTable(tableName); | ||
|
||
// Deletes the table | ||
await serviceClient.deleteTable(tableName); | ||
} | ||
|
||
async function createAndDeleteTableWithTableClient() { | ||
// A table can also be created and deleted using a TableClient | ||
console.log("== Delete and create table with TableClient Sample =="); | ||
|
||
const tableName = "SampleCreateAndDeleteTable2"; | ||
|
||
// Creating a new table client doesn't do a network call | ||
const client = TableClient.fromConnectionString(sasConnectionString, tableName); | ||
|
||
// Will attempt to create a table with the tableName specified above | ||
await client.createTable(); | ||
|
||
// Will attempt to delete the table with the tableName specified above | ||
await client.deleteTable(); | ||
} | ||
|
||
async function main() { | ||
await createAndDeleteTable(); | ||
await createAndDeleteTableWithTableClient(); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error("The sample encountered an error:", err); | ||
}); |
Oops, something went wrong.