Trying to pass a variable in .having()

My having clause is like this:

.having(
({ endAt }) =>
sqldate_trunc('day', ${subEndAt}) = CURRENT_DATE + INTERVAL ${sql${intervalDays}},
);

I am fetching endAt in the query, but I have multiple intervals like '3 days', '5 days'.

When I try passing intervalDays as string i get an syntax error, but instead of intervalDays if I set it as 3 days the query works fine.

Is there a way where we can pass it using a variable or do we need to create a separate query for each of the intervals?
Was this page helpful?