Skip to content

Commit b8c4ac2

Browse files
authored
Add upsert operation to BatchClient and upgrade samples (Azure#14799)
* Add upsert operation to BatchClient and upgrade samples * delete legacy samples * Remove locale * Fix links * Fix samples logger issue * Re-publish samples
1 parent 3197aef commit b8c4ac2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1247
-252
lines changed

sdk/tables/data-tables/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
"build:autorest": "autorest ./swagger/README.md --typescript --package-version=1.0.0-beta.4 --version=3.0.6267 --v3=true",
1919
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
2020
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
21-
"build:samples": "dev-tool samples prep && cd dist-samples && tsc",
21+
"build:samples": "echo Obsolete.",
2222
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
2323
"build:types": "downlevel-dts types/latest types/3.1",
2424
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
2525
"check-format": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
2626
"clean": "rimraf dist dist-* types *.tgz *.log",
27-
"execute:samples": "echo Skipped.",
27+
"execute:samples": "dev-tool samples run samples-dev",
2828
"extract-api": "tsc -p . && api-extractor run --local",
2929
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
3030
"integration-test:browser": "karma start --single-run --testMode=integration",
@@ -125,6 +125,16 @@
125125
"ts-node": "^9.0.0",
126126
"typedoc": "0.15.2"
127127
},
128+
"//sampleConfiguration": {
129+
"productName": "Azure Data Tables",
130+
"productSlugs": [
131+
"azure",
132+
"azure-table-storage"
133+
],
134+
"requiredResources": {
135+
"Azure Storage instance": "https://docs.microsoft.com/azure/storage/tables/table-storage-quickstart-portal"
136+
}
137+
},
128138
"//metadata": {
129139
"constantPaths": [
130140
{

sdk/tables/data-tables/recordings/browsers/batch_operations/recording_should_send_a_set_of_upsert_batch_operations.json

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/tables/data-tables/recordings/node/batch_operations/recording_should_send_a_set_of_upsert_batch_operations.js

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/tables/data-tables/review/data-tables.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export interface TableBatch {
244244
partitionKey: string;
245245
submitBatch: () => Promise<TableBatchResponse>;
246246
updateEntity: <T extends object>(entity: TableEntity<T>, mode: UpdateMode, options?: UpdateTableEntityOptions) => void;
247+
upsertEntity: <T extends object>(entity: TableEntity<T>, mode: UpdateMode, options?: UpsertTableEntityOptions) => void;
247248
}
248249

249250
// @public
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
/**
5+
* This sample demonstrates how to use the different methods of authentication
6+
* to make calls to the Azure Tables Service
7+
*
8+
* @summary authenticates using different authentication methods
9+
* @azsdk-weight 40
10+
*/
11+
import { TableServiceClient, TablesSharedKeyCredential } from "@azure/data-tables";
12+
13+
// Load the .env file if it exists
14+
import * as dotenv from "dotenv";
15+
dotenv.config();
16+
17+
// URL of the tables endpoint
18+
const tablesUrl = process.env["TABLES_URL"] || "";
19+
20+
// You can find your storage account's name, connection strings and keys in the Azure portal.
21+
// Navigate to Settings > Access keys in your storage account's menu blade to see connection strings for both primary and secondary access keys
22+
const accountConnectionString = process.env["ACCOUNT_CONNECTION_STRING"] || "";
23+
const accountName = process.env["ACCOUNT_NAME"] || "";
24+
const accountKey = process.env["ACCOUNT_KEY"] || "";
25+
26+
// You can generate a SAS connection string and token for your storage account in the Azure Portal
27+
// Navigate to Settings > "Shared access signature" in your storage account's menu blade select the Allowed services, resource types, permissions and expiry options
28+
// and generate your SAS and connection string.
29+
const sasConnectionString = process.env["SAS_CONNECTION_STRING"] || "";
30+
const sasToken = process.env["SAS_TOKEN"] || "";
31+
32+
/**
33+
* Create a TableServiceCLient using a SAS connection String
34+
*/
35+
async function tableServiceClientWithSasConnectionString() {
36+
const client = TableServiceClient.fromConnectionString(sasConnectionString);
37+
countTablesWithClient(client);
38+
}
39+
40+
/**
41+
* Create a TableServiceCLient using a SAS token
42+
*/
43+
async function tableServiceClientWithSasToken() {
44+
const client = new TableServiceClient(`${tablesUrl}${sasToken}`);
45+
countTablesWithClient(client);
46+
}
47+
48+
/**
49+
* Create a TableServiceCLient using an Account connection String.
50+
* Note that this authentication method is only supported in Node,
51+
* and it is not available for browsers
52+
*/
53+
async function tableServiceClientWithAccountConnectionString() {
54+
const client = TableServiceClient.fromConnectionString(accountConnectionString);
55+
countTablesWithClient(client);
56+
}
57+
58+
/**
59+
* Create a TableServiceCLient using account name and account key
60+
* Note that this authentication method is only supported in Node,
61+
* and it is not available for browsers
62+
*/
63+
async function tableServiceClientWithAccountKey() {
64+
const creds = new TablesSharedKeyCredential(accountName, accountKey);
65+
const client = new TableServiceClient(tablesUrl, creds);
66+
countTablesWithClient(client);
67+
}
68+
69+
async function countTablesWithClient(client: TableServiceClient) {
70+
const tablesIterator = client.listTables();
71+
let count = 0;
72+
for await (const _table of tablesIterator) {
73+
count++;
74+
}
75+
76+
console.log(`Listed ${count} tables`);
77+
}
78+
79+
export async function main() {
80+
console.log("== Client Authentication Methods Sample ==");
81+
82+
await tableServiceClientWithSasConnectionString();
83+
await tableServiceClientWithSasToken();
84+
85+
await tableServiceClientWithAccountConnectionString();
86+
await tableServiceClientWithAccountKey();
87+
}
88+
89+
main().catch((err) => {
90+
console.error("The sample encountered an error:", err);
91+
});

0 commit comments

Comments
 (0)