/
query.js
37 lines (31 loc) · 1.35 KB
/
query.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
29
30
31
32
33
34
35
36
37
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { fileURLToPath } from "url";
// snippet-start:[dynamodb.JavaScript.table.queryV3]
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";
const client = new DynamoDBClient({});
export const main = async () => {
const command = new QueryCommand({
KeyConditionExpression: "Flavor = :flavor",
// For more information about data types,
// see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes and
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.LowLevelAPI.html#Programming.LowLevelAPI.DataTypeDescriptors
ExpressionAttributeValues: {
":flavor": { S: "Key Lime" },
":searchKey": { S: "no coloring" },
},
FilterExpression: "contains (Description, :searchKey)",
ProjectionExpression: "Flavor, CrustType, Description",
TableName: "Pies",
});
const response = await client.send(command);
response.Items.forEach(function (pie) {
console.log(`${pie.Flavor.S} - ${pie.Description.S}\n`);
});
return response;
};
// snippet-end:[dynamodb.JavaScript.table.queryV3]
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
main();
}