@factorearth/recordmiddleware-dataaccesslayer 0.0.1-alpha.18 → 0.0.1-alpha.19
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/lib/getItem.ts +26 -2
- package/package.json +2 -2
package/lib/getItem.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { dynamoDbDocClient } from "./aws-services.js";
|
|
2
|
-
import { GetCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { GetCommand, GetCommandInput, QueryCommand, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
|
3
3
|
|
|
4
4
|
export const getItem = async (id: string, tableName: string) => {
|
|
5
|
-
const params = {
|
|
5
|
+
const params: GetCommandInput = {
|
|
6
6
|
TableName: tableName,
|
|
7
7
|
Key: {
|
|
8
8
|
id
|
|
@@ -15,4 +15,28 @@ export const getItem = async (id: string, tableName: string) => {
|
|
|
15
15
|
console.error("Error", err);
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getItemsByIndex = async (indexName: string, tableName: string, fk:string, expression: string) => {
|
|
21
|
+
|
|
22
|
+
const params: QueryCommandInput = {
|
|
23
|
+
TableName: tableName,
|
|
24
|
+
IndexName: indexName,
|
|
25
|
+
KeyConditionExpression: `fk = :${expression}`,
|
|
26
|
+
ExpressionAttributeNames: {
|
|
27
|
+
"fk" : `${expression}`
|
|
28
|
+
},
|
|
29
|
+
ExpressionAttributeValues: {
|
|
30
|
+
"fkval": fk
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const data = await dynamoDbDocClient.send(new QueryCommand(params));
|
|
36
|
+
return data.Items || [];
|
|
37
|
+
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error("Error", err);
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
18
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorearth/recordmiddleware-dataaccesslayer",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.19",
|
|
4
4
|
"description": "A module for accessing dynamdb efficiently",
|
|
5
5
|
"author": "madtrx <marlin.makori@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/FactorEarth/RecordMiddleware#readme",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"access": "public",
|
|
30
30
|
"registry": "https://registry.npmjs.org/"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "1c5b87e393d40f2d5df710a0640e7c3505ffb04f"
|
|
33
33
|
}
|