@aws-sdk/lib-dynamodb 3.850.0 → 3.856.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -303,6 +303,77 @@ await impreciseClient.send(
|
|
|
303
303
|
);
|
|
304
304
|
```
|
|
305
305
|
|
|
306
|
+
### Example: performing a full table scan
|
|
307
|
+
|
|
308
|
+
Before performing a full table scan, consider whether your query can be satisfied by a more efficient operation.
|
|
309
|
+
For instance, if you are searching for a set of rows by primary keys, `BatchGetItem` may be better.
|
|
310
|
+
|
|
311
|
+
First, initialize the base Client and Document Client.
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
315
|
+
import { DynamoDBDocumentClient, paginateScan, ScanCommand } from "@aws-sdk/lib-dynamodb";
|
|
316
|
+
|
|
317
|
+
const client = new DynamoDBClient({
|
|
318
|
+
region: "us-west-2",
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const docClient = DynamoDBDocumentClient.from(client);
|
|
322
|
+
|
|
323
|
+
const paginatorConfiguration = {
|
|
324
|
+
client: docClient,
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* This is a function so as to create
|
|
329
|
+
* separate objects per request.
|
|
330
|
+
*
|
|
331
|
+
* The objects passed into AWS SDK Command instances
|
|
332
|
+
* are retained as references, so this prevents unexpected mutations.
|
|
333
|
+
*/
|
|
334
|
+
const scanRequestInput = () => ({
|
|
335
|
+
TableName: "YOUR_TABLE_NAME",
|
|
336
|
+
Limit: 100,
|
|
337
|
+
});
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The recommended way to iterate the scan is with our library's paginator helper function.
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
// Recommended method, using the AWS SDK paginator:
|
|
344
|
+
let pageNumber = 1;
|
|
345
|
+
for await (const page of paginateScan(paginatorConfiguration, scanRequestInput())) {
|
|
346
|
+
console.log("page:", pageNumber++);
|
|
347
|
+
console.log(page.Items);
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Alternatively, the equivalent manual method, which is exactly what the paginator function
|
|
352
|
+
is doing internally, is with a loop utilizing the pagination token from the responses:
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
// Manual method, using the ScanCommand and pagination token:
|
|
356
|
+
let pageNumber = 1;
|
|
357
|
+
const firstPage = await docClient.send(new ScanCommand(scanRequestInput()));
|
|
358
|
+
console.log("page:", pageNumber++);
|
|
359
|
+
console.log(firstPage.Items);
|
|
360
|
+
|
|
361
|
+
let paginationToken = firstPage.LastEvaluatedKey;
|
|
362
|
+
|
|
363
|
+
while (paginationToken) {
|
|
364
|
+
const page = await docClient.send(
|
|
365
|
+
new ScanCommand({
|
|
366
|
+
...scanRequestInput(),
|
|
367
|
+
ExclusiveStartKey: paginationToken,
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
paginationToken = page.LastEvaluatedKey;
|
|
371
|
+
|
|
372
|
+
console.log("page:", pageNumber++);
|
|
373
|
+
console.log(page.Items);
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
306
377
|
### Client and Command middleware stacks
|
|
307
378
|
|
|
308
379
|
As with other AWS SDK for JavaScript v3 clients, you can apply middleware functions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/lib-dynamodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.856.0",
|
|
4
4
|
"description": "The document client simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values.",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aws-sdk/core": "3.
|
|
34
|
-
"@aws-sdk/util-dynamodb": "3.
|
|
33
|
+
"@aws-sdk/core": "3.856.0",
|
|
34
|
+
"@aws-sdk/util-dynamodb": "3.856.0",
|
|
35
35
|
"@smithy/core": "^3.7.0",
|
|
36
36
|
"@smithy/smithy-client": "^4.4.7",
|
|
37
37
|
"@smithy/types": "^4.3.1",
|
|
38
38
|
"tslib": "^2.6.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
41
|
+
"@aws-sdk/client-dynamodb": "^3.856.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
44
|
+
"@aws-sdk/client-dynamodb": "3.856.0",
|
|
45
45
|
"@tsconfig/recommended": "1.0.1",
|
|
46
46
|
"@types/node": "^18.19.69",
|
|
47
47
|
"concurrently": "7.0.0",
|