Skip to content

Commit 859913d

Browse files
authored
[Tables] Fix typos in samples (Azure#13072)
Fixes Azure#12914 . Also adding a sample on how to query topN items
1 parent cd97a78 commit 859913d

File tree

7 files changed

+83
-19
lines changed

7 files changed

+83
-19
lines changed

sdk/tables/data-tables/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 1.0.0-beta.4 (Unreleased)
3+
## 1.0.0-beta.4 (2021-01-12)
44

55
### Breaking Changes
66

sdk/tables/data-tables/samples/javascript/src/batchOperations.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,16 @@ async function batchOperations() {
5858
// [
5959
// {
6060
// status: 204,
61-
// body: undefined,
6261
// rowKey: 'A1',
6362
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
6463
// },
6564
// {
6665
// status: 204,
67-
// body: undefined,
6866
// rowKey: 'A2',
6967
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
7068
// },
7169
// {
7270
// status: 204,
73-
// body: undefined,
7471
// rowKey: 'A3',
7572
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
7673
// }

sdk/tables/data-tables/samples/javascript/src/queryEntities.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dotenv.config();
1010
const tablesUrl = process.env["TABLES_URL"] || "";
1111
const sasToken = process.env["SAS_TOKEN"] || "";
1212

13-
async function createAndDeleteEntities() {
14-
console.log("== Create and delete entities Sample ==");
13+
async function listEntities() {
14+
console.log("== List entities Sample ==");
1515

1616
// Note that this sample assumes that a table with tableName exists
1717
const tableName = "OfficeSupplies4p1";
@@ -60,8 +60,43 @@ async function createAndDeleteEntities() {
6060
}
6161
}
6262

63+
// Sample of how to retreive the top N entities for a query
64+
async function listTopNEntities() {
65+
// This is the max number of items
66+
const topN = 1;
67+
const partitionKey = "Stationery";
68+
69+
// Note that this sample assumes that a table with tableName exists
70+
const tableName = "OfficeSupplies4p1";
71+
72+
// See authenticationMethods sample for other options of creating a new client
73+
const client = new TableClient(`${tablesUrl}${sasToken}`, tableName);
74+
75+
// List all entities with PartitionKey "Stationery"
76+
const listResults = client.listEntities({
77+
queryOptions: {
78+
filter: odata`PartitionKey eq ${partitionKey}`
79+
}
80+
});
81+
82+
let topEntities = [];
83+
const iterator = listResults.byPage({ maxPageSize: topN });
84+
85+
for await (const page of iterator) {
86+
// Take the first page as the topEntires result
87+
topEntities = page;
88+
// We break to only get the first page
89+
// this only sends a single request to the service
90+
break;
91+
}
92+
93+
console.log(`Top entities: ${topEntities.length}`);
94+
// Top entities: 1
95+
}
96+
6397
async function main() {
64-
await createAndDeleteEntities();
98+
await listEntities();
99+
await listTopNEntities();
65100
}
66101

67102
main().catch((err) => {

sdk/tables/data-tables/samples/javascript/src/updateAndUpsertEntities.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dotenv.config();
1010
const tablesUrl = process.env["TABLES_URL"] || "";
1111
const sasToken = process.env["SAS_TOKEN"] || "";
1212

13-
async function createAndDeleteEntities() {
14-
console.log("== Create and delete entities Sample ==");
13+
async function updateAndUpsertEntities() {
14+
console.log("== Update and Upsert entities Sample ==");
1515

1616
// Note that this sample assumes that a table with tableName exists
1717
const tableName = "OfficeSupplies5p1";
@@ -50,7 +50,7 @@ async function createAndDeleteEntities() {
5050
}
5151

5252
async function main() {
53-
await createAndDeleteEntities();
53+
await updateAndUpsertEntities();
5454
}
5555

5656
main().catch((err) => {

sdk/tables/data-tables/samples/typescript/src/batchOperations.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,16 @@ async function batchOperations() {
6666
// [
6767
// {
6868
// status: 204,
69-
// body: undefined,
7069
// rowKey: 'A1',
7170
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
7271
// },
7372
// {
7473
// status: 204,
75-
// body: undefined,
7674
// rowKey: 'A2',
7775
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
7876
// },
7977
// {
8078
// status: 204,
81-
// body: undefined,
8279
// rowKey: 'A3',
8380
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
8481
// }

sdk/tables/data-tables/samples/typescript/src/queryEntities.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dotenv.config();
1010
const tablesUrl = process.env["TABLES_URL"] || "";
1111
const sasToken = process.env["SAS_TOKEN"] || "";
1212

13-
async function createAndDeleteEntities() {
14-
console.log("== Create and delete entities Sample ==");
13+
async function listEntities() {
14+
console.log("== List entities Sample ==");
1515

1616
// Note that this sample assumes that a table with tableName exists
1717
const tableName = "OfficeSupplies4p1";
@@ -60,6 +60,40 @@ async function createAndDeleteEntities() {
6060
}
6161
}
6262

63+
// Sample of how to retreive the top N entities for a query
64+
async function listTopNEntities() {
65+
// This is the max number of items
66+
const topN = 1;
67+
const partitionKey = "Stationery";
68+
69+
// Note that this sample assumes that a table with tableName exists
70+
const tableName = "OfficeSupplies4p1";
71+
72+
// See authenticationMethods sample for other options of creating a new client
73+
const client = new TableClient(`${tablesUrl}${sasToken}`, tableName);
74+
75+
// List all entities with PartitionKey "Stationery"
76+
const listResults = client.listEntities<Entity>({
77+
queryOptions: {
78+
filter: odata`PartitionKey eq ${partitionKey}`
79+
}
80+
});
81+
82+
let topEntities = [];
83+
const iterator = listResults.byPage({ maxPageSize: topN });
84+
85+
for await (const page of iterator) {
86+
// Take the first page as the topEntires result
87+
topEntities = page;
88+
// We break to only get the first page
89+
// this only sends a single request to the service
90+
break;
91+
}
92+
93+
console.log(`Top entities: ${topEntities.length}`);
94+
// Top entities: 1
95+
}
96+
6397
interface Entity {
6498
partitionKey: string;
6599
rowKey: string;
@@ -69,7 +103,8 @@ interface Entity {
69103
}
70104

71105
export async function main() {
72-
await createAndDeleteEntities();
106+
await listEntities();
107+
await listTopNEntities();
73108
}
74109

75110
main().catch((err) => {

sdk/tables/data-tables/samples/typescript/src/updateAndUpsertEntities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dotenv.config();
1010
const tablesUrl = process.env["TABLES_URL"] || "";
1111
const sasToken = process.env["SAS_TOKEN"] || "";
1212

13-
async function createAndDeleteEntities() {
14-
console.log("== Create and delete entities Sample ==");
13+
async function updateAndUpsertEntities() {
14+
console.log("== Update and Upsert entities Sample ==");
1515

1616
// Note that this sample assumes that a table with tableName exists
1717
const tableName = "OfficeSupplies5p1";
@@ -58,7 +58,7 @@ interface Entity {
5858
}
5959

6060
export async function main() {
61-
await createAndDeleteEntities();
61+
await updateAndUpsertEntities();
6262
}
6363

6464
main().catch((err) => {

0 commit comments

Comments
 (0)