I want to make a function Where for my DynamoDb collection, like LINQ Where.
I want to do it with QueryRequest or ScanRequest.
Is there any information on how to do this?
CodePudding user response:
This isn’t really “the way” with DynamoDB. You need to think about access patterns when you write your data. The main thing you’re going to need to read up on are secondary indices (start here).
If you want a relational database then you can achieve that with DynamoDB but you have to work for it. You get incredible scaling but you have to do some careful thinking up front. Here is a good article on relational design.
CodePudding user response:
If you want to use WHERE
or SQL like expressions with DynamoDB then you can do so using PartiQL which is a SQL wrapper around DynamoDB low level API.
ExecuteStatement
is the API call you make and would look like the following:
// Import required AWS SDK clients and commands for Node.js.
import { ExecuteStatementCommand } from "@aws-sdk/client-dynamodb";
import { ddbDocClient } from "../libs/ddbDocClient";
const tableName = process.argv[2];
export const run = async (tableName) => {
const params = {
Statement: "SELECT * FROM " tableName " where title ='Top Gun'"
};
try {
const data = await ddbDocClient.send(new ExecuteStatementCommand(params));
console.log(data);
return "Run successfully"; // For unit tests.
} catch (err) {
console.error(err);
}
};
run(tableName);