-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathexecute-statement.js
28 lines (23 loc) · 1.11 KB
/
execute-statement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const REGION = "us-west-2";
// I am using the DynamoDB low level because the DocClient does not support executeStatement used with PartiQL
const { DynamoDB } = require("@aws-sdk/client-dynamodb");
const { unmarshall } = require("@aws-sdk/util-dynamodb");
// Create low level client
const dbclient = new DynamoDB({ region: REGION });
const pk = "TEAM";
// In PartiQL, we can execute statement with execute-statement which performs one action similar to Scan/Query.
const params = { Statement: `SELECT * FROM "copa-america" WHERE "pk" = ?`,
Parameters: [{"S": pk}]
};
const executePartiQLStatement = async () => {
return data = await dbclient.executeStatement(params);
}
executePartiQLStatement()
.then((data) => {
//Iterate through the Items array returned in the data variable and then unmarshall the DynamoDB JSON format to "regular" json format.
data.Items.forEach(function (item) {
console.log(JSON.stringify(unmarshall(item), null, 2));
});
}
)
.catch((error) => console.error(JSON.stringify(error, null, 2)));