Javascript DynamoDB:检索数据的动态函数
如何使用Node.js创建一个动态函数,使用query方法从AWS DynamoDB检索数据? 函数应该能够获取参数,如TableName、IndexName、Key、Value、SortKey、SortValue、Filter、FilterValue、SecondFilter、SecondFildValue、ScanIndexForward、Limit。支持从表中获取所有项的功能将非常好,因为DynamoDB查询只检索部分项Javascript DynamoDB:检索数据的动态函数,javascript,node.js,amazon-web-services,amazon-dynamodb,amazon-dynamodb-index,Javascript,Node.js,Amazon Web Services,Amazon Dynamodb,Amazon Dynamodb Index,如何使用Node.js创建一个动态函数,使用query方法从AWS DynamoDB检索数据? 函数应该能够获取参数,如TableName、IndexName、Key、Value、SortKey、SortValue、Filter、FilterValue、SecondFilter、SecondFildValue、ScanIndexForward、Limit。支持从表中获取所有项的功能将非常好,因为DynamoDB查询只检索部分项 提前感谢。您看过AWS github示例repo中的JavaScri
提前感谢。您看过AWS github示例repo中的JavaScript示例了吗?如果没有,您可以在这里找到它们:您看过AWS github示例repo中的JavaScript示例了吗?如果没有,您将在此处找到它们:这里是一个示例,您可以修改并添加所需的参数
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
ABOUT THIS NODE.JS EXAMPLE: This example works with AWS SDK for JavaScript version 3 (v3),
which is available at https://github.com/aws/aws-sdk-js-v3. This example is in the 'AWS SDK for JavaScript v3 Developer Guide' at
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/dynamodb-example-query-scan.html.
Purpose:
ddb_query.ts demonstrates how to find items in an Amazon DynamoDB table.
Inputs (replace in code):
- REGION
Running the code:
ts-node ddb_query.ts
*/
// snippet-start:[dynamodb.JavaScript.table.queryV3]
// Import required AWS SDK clients and commands for Node.js
const { DynamoDBClient, QueryCommand } = require("@aws-sdk/client-dynamodb");
// Set the AWS Region
const REGION = "region"; //e.g. "us-east-1"
// Set the parameters
const params = {
KeyConditionExpression: "Season = :s and Episode > :e",
FilterExpression: "contains (Subtitle, :topic)",
ExpressionAttributeValues: {
":s": { N: "1" },
":e": { N: "2" },
":topic": { S: "SubTitle" },
},
ProjectionExpression: "Episode, Title, Subtitle",
TableName: "EPISODES_TABLE",
};
// Create DynamoDB service object
const dbclient = new DynamoDBClient({ region: REGION });
const run = async () => {
try {
const results = await dbclient.send(new QueryCommand(params));
results.Items.forEach(function (element, index, array) {
console.log(element.Title.S + " (" + element.Subtitle.S + ")");
});
} catch (err) {
console.error(err);
}
};
run();
// snippet-end:[dynamodb.JavaScript.table.queryV3]
下面是一个示例,您可以修改和添加所需的参数
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
ABOUT THIS NODE.JS EXAMPLE: This example works with AWS SDK for JavaScript version 3 (v3),
which is available at https://github.com/aws/aws-sdk-js-v3. This example is in the 'AWS SDK for JavaScript v3 Developer Guide' at
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/dynamodb-example-query-scan.html.
Purpose:
ddb_query.ts demonstrates how to find items in an Amazon DynamoDB table.
Inputs (replace in code):
- REGION
Running the code:
ts-node ddb_query.ts
*/
// snippet-start:[dynamodb.JavaScript.table.queryV3]
// Import required AWS SDK clients and commands for Node.js
const { DynamoDBClient, QueryCommand } = require("@aws-sdk/client-dynamodb");
// Set the AWS Region
const REGION = "region"; //e.g. "us-east-1"
// Set the parameters
const params = {
KeyConditionExpression: "Season = :s and Episode > :e",
FilterExpression: "contains (Subtitle, :topic)",
ExpressionAttributeValues: {
":s": { N: "1" },
":e": { N: "2" },
":topic": { S: "SubTitle" },
},
ProjectionExpression: "Episode, Title, Subtitle",
TableName: "EPISODES_TABLE",
};
// Create DynamoDB service object
const dbclient = new DynamoDBClient({ region: REGION });
const run = async () => {
try {
const results = await dbclient.send(new QueryCommand(params));
results.Items.forEach(function (element, index, array) {
console.log(element.Title.S + " (" + element.Subtitle.S + ")");
});
} catch (err) {
console.error(err);
}
};
run();
// snippet-end:[dynamodb.JavaScript.table.queryV3]
你试过什么?你被困在哪里?就目前情况而言,这个问题听起来像是你希望有人为你做这项工作。你试过什么?你被困在哪里?就目前而言,这个问题听起来像是你想要有人为你做这项工作。