[Tables] Fix typos in samples (#13072)
Fixes #12914 . Also adding a sample on how to query topN items
This commit is contained in:
Родитель
cd97a786e8
Коммит
859913d019
|
@ -1,6 +1,6 @@
|
|||
# Release History
|
||||
|
||||
## 1.0.0-beta.4 (Unreleased)
|
||||
## 1.0.0-beta.4 (2021-01-12)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
|
|
|
@ -58,19 +58,16 @@ async function batchOperations() {
|
|||
// [
|
||||
// {
|
||||
// status: 204,
|
||||
// body: undefined,
|
||||
// rowKey: 'A1',
|
||||
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
|
||||
// },
|
||||
// {
|
||||
// status: 204,
|
||||
// body: undefined,
|
||||
// rowKey: 'A2',
|
||||
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
|
||||
// },
|
||||
// {
|
||||
// status: 204,
|
||||
// body: undefined,
|
||||
// rowKey: 'A3',
|
||||
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
|
||||
// }
|
||||
|
|
|
@ -10,8 +10,8 @@ dotenv.config();
|
|||
const tablesUrl = process.env["TABLES_URL"] || "";
|
||||
const sasToken = process.env["SAS_TOKEN"] || "";
|
||||
|
||||
async function createAndDeleteEntities() {
|
||||
console.log("== Create and delete entities Sample ==");
|
||||
async function listEntities() {
|
||||
console.log("== List entities Sample ==");
|
||||
|
||||
// Note that this sample assumes that a table with tableName exists
|
||||
const tableName = "OfficeSupplies4p1";
|
||||
|
@ -60,8 +60,43 @@ async function createAndDeleteEntities() {
|
|||
}
|
||||
}
|
||||
|
||||
// Sample of how to retreive the top N entities for a query
|
||||
async function listTopNEntities() {
|
||||
// This is the max number of items
|
||||
const topN = 1;
|
||||
const partitionKey = "Stationery";
|
||||
|
||||
// Note that this sample assumes that a table with tableName exists
|
||||
const tableName = "OfficeSupplies4p1";
|
||||
|
||||
// See authenticationMethods sample for other options of creating a new client
|
||||
const client = new TableClient(`${tablesUrl}${sasToken}`, tableName);
|
||||
|
||||
// List all entities with PartitionKey "Stationery"
|
||||
const listResults = client.listEntities({
|
||||
queryOptions: {
|
||||
filter: odata`PartitionKey eq ${partitionKey}`
|
||||
}
|
||||
});
|
||||
|
||||
let topEntities = [];
|
||||
const iterator = listResults.byPage({ maxPageSize: topN });
|
||||
|
||||
for await (const page of iterator) {
|
||||
// Take the first page as the topEntires result
|
||||
topEntities = page;
|
||||
// We break to only get the first page
|
||||
// this only sends a single request to the service
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`Top entities: ${topEntities.length}`);
|
||||
// Top entities: 1
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await createAndDeleteEntities();
|
||||
await listEntities();
|
||||
await listTopNEntities();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
|
|
|
@ -10,8 +10,8 @@ dotenv.config();
|
|||
const tablesUrl = process.env["TABLES_URL"] || "";
|
||||
const sasToken = process.env["SAS_TOKEN"] || "";
|
||||
|
||||
async function createAndDeleteEntities() {
|
||||
console.log("== Create and delete entities Sample ==");
|
||||
async function updateAndUpsertEntities() {
|
||||
console.log("== Update and Upsert entities Sample ==");
|
||||
|
||||
// Note that this sample assumes that a table with tableName exists
|
||||
const tableName = "OfficeSupplies5p1";
|
||||
|
@ -50,7 +50,7 @@ async function createAndDeleteEntities() {
|
|||
}
|
||||
|
||||
async function main() {
|
||||
await createAndDeleteEntities();
|
||||
await updateAndUpsertEntities();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
|
|
|
@ -66,19 +66,16 @@ async function batchOperations() {
|
|||
// [
|
||||
// {
|
||||
// status: 204,
|
||||
// body: undefined,
|
||||
// rowKey: 'A1',
|
||||
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
|
||||
// },
|
||||
// {
|
||||
// status: 204,
|
||||
// body: undefined,
|
||||
// rowKey: 'A2',
|
||||
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
|
||||
// },
|
||||
// {
|
||||
// status: 204,
|
||||
// body: undefined,
|
||||
// rowKey: 'A3',
|
||||
// etag: `W/"datetime'2020-10-02T03%3A31%3A09.9324186Z'"`
|
||||
// }
|
||||
|
|
|
@ -10,8 +10,8 @@ dotenv.config();
|
|||
const tablesUrl = process.env["TABLES_URL"] || "";
|
||||
const sasToken = process.env["SAS_TOKEN"] || "";
|
||||
|
||||
async function createAndDeleteEntities() {
|
||||
console.log("== Create and delete entities Sample ==");
|
||||
async function listEntities() {
|
||||
console.log("== List entities Sample ==");
|
||||
|
||||
// Note that this sample assumes that a table with tableName exists
|
||||
const tableName = "OfficeSupplies4p1";
|
||||
|
@ -60,6 +60,40 @@ async function createAndDeleteEntities() {
|
|||
}
|
||||
}
|
||||
|
||||
// Sample of how to retreive the top N entities for a query
|
||||
async function listTopNEntities() {
|
||||
// This is the max number of items
|
||||
const topN = 1;
|
||||
const partitionKey = "Stationery";
|
||||
|
||||
// Note that this sample assumes that a table with tableName exists
|
||||
const tableName = "OfficeSupplies4p1";
|
||||
|
||||
// See authenticationMethods sample for other options of creating a new client
|
||||
const client = new TableClient(`${tablesUrl}${sasToken}`, tableName);
|
||||
|
||||
// List all entities with PartitionKey "Stationery"
|
||||
const listResults = client.listEntities<Entity>({
|
||||
queryOptions: {
|
||||
filter: odata`PartitionKey eq ${partitionKey}`
|
||||
}
|
||||
});
|
||||
|
||||
let topEntities = [];
|
||||
const iterator = listResults.byPage({ maxPageSize: topN });
|
||||
|
||||
for await (const page of iterator) {
|
||||
// Take the first page as the topEntires result
|
||||
topEntities = page;
|
||||
// We break to only get the first page
|
||||
// this only sends a single request to the service
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`Top entities: ${topEntities.length}`);
|
||||
// Top entities: 1
|
||||
}
|
||||
|
||||
interface Entity {
|
||||
partitionKey: string;
|
||||
rowKey: string;
|
||||
|
@ -69,7 +103,8 @@ interface Entity {
|
|||
}
|
||||
|
||||
export async function main() {
|
||||
await createAndDeleteEntities();
|
||||
await listEntities();
|
||||
await listTopNEntities();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
|
|
|
@ -10,8 +10,8 @@ dotenv.config();
|
|||
const tablesUrl = process.env["TABLES_URL"] || "";
|
||||
const sasToken = process.env["SAS_TOKEN"] || "";
|
||||
|
||||
async function createAndDeleteEntities() {
|
||||
console.log("== Create and delete entities Sample ==");
|
||||
async function updateAndUpsertEntities() {
|
||||
console.log("== Update and Upsert entities Sample ==");
|
||||
|
||||
// Note that this sample assumes that a table with tableName exists
|
||||
const tableName = "OfficeSupplies5p1";
|
||||
|
@ -58,7 +58,7 @@ interface Entity {
|
|||
}
|
||||
|
||||
export async function main() {
|
||||
await createAndDeleteEntities();
|
||||
await updateAndUpsertEntities();
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче