@plusscommunities/pluss-core-aws 1.6.8 → 1.6.9
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/db/common/scanRefRecursive.js +24 -21
- package/package.json +1 -1
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
1
|
const scanRef = require("./scanRef");
|
|
3
2
|
|
|
4
|
-
const scanRefRecursive = (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (result) {
|
|
11
|
-
tempResult = _.concat(tempResult, result.Items);
|
|
12
|
-
if (!result.LastEvaluatedKey) {
|
|
13
|
-
return resolve(tempResult);
|
|
14
|
-
} else {
|
|
15
|
-
lastKey = result.LastEvaluatedKey;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
3
|
+
const scanRefRecursive = async (tableName, query, startKey) => {
|
|
4
|
+
if (!query) {
|
|
5
|
+
query = {};
|
|
6
|
+
}
|
|
7
|
+
// Set the ExclusiveStartKey in the params
|
|
8
|
+
query.ExclusiveStartKey = startKey;
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
// Perform the scan and await the results
|
|
11
|
+
const data = await scanRef(tableName, query);
|
|
12
|
+
|
|
13
|
+
// Extract the Items from the results
|
|
14
|
+
let items = data.Items;
|
|
15
|
+
|
|
16
|
+
// If the LastEvaluatedKey is present, that means there are more items to fetch
|
|
17
|
+
if (data.LastEvaluatedKey) {
|
|
18
|
+
// Recursively call the function to fetch the next batch of items, and await the results
|
|
19
|
+
// Concatenate the new items with the ones we have already fetched
|
|
20
|
+
items = [
|
|
21
|
+
...items,
|
|
22
|
+
...(await scanRefRecursive(tableName, query, data.LastEvaluatedKey)),
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Return the complete list of items
|
|
27
|
+
return items;
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
module.exports = scanRefRecursive;
|