Currently we have it set up such that the start date and end date are required to query results, looking something like this.
interface GetStuffIdArgs extends DdbPaginationQueryArgs {
// Required query params
startTime: string;
endTime: string;
async getOtherStuff(id: string | number, args: GetOtherStuffIdArgs) {
const { startTime, endTime, id, someType, order = "DESC" } = args;
// convert times to ISO (utc 0);
const startTimeISO = new Date(startTime).toISOString();
const endTimeISO = new Date(endTime).toISOString();
/**
* Query between start and end time
*/
KeyConditionExpression: `${this.PK} = :pk and ${this.SK} BETWEEN :starttime AND :endtime`
I've tried a few things that I thought could make the parameter optional but am not sure how the query itself would change based off of it.
interface GetStuffIdArgs extends DdbPaginationQueryArgs {
// Required query params
startTime: string;
endTime: string | null;
async getOtherStuff(id: string | number, args: GetOtherStuffIdArgs) {
const { startTime, endTime, id, someType, order = "DESC" } = args;
// convert times to ISO (utc 0);
const startTimeISO = new Date(startTime).toISOString();
const endTimeISO = endTime ? new Date(endTime).toISOString() : null;
If this is even the correct way, I'm not quite sure how to make the query change based off of it.
First time I've ever looked at dynamodb. I'm curious how I can make the :et
optional such that if it is null, it will simply query everything from the start date and on? Perhaps the better question would be: is it possible to make the KeyConditionExpression conditional such that it could be one of two things depending on params?