Kaz ^v^
DTDrizzle Team
•Created by Kaz ^v^ on 3/1/2024 in #help
Trying to pass a variable in .having()
this works, thanks @solo
8 replies
DTDrizzle Team
•Created by Kaz ^v^ on 3/1/2024 in #help
Trying to pass a variable in .having()
@solo any idea how to do it?
8 replies
DTDrizzle Team
•Created by Kaz ^v^ on 3/1/2024 in #help
Trying to pass a variable in .having()
but it works fine if i hardcode the interval before hand like,
.having(({ endAt }) =>
sqldate_trunc('day', ${subEndAt}) = CURRENT_DATE + INTERVAL '14 days'},
);
8 replies
DTDrizzle Team
•Created by Kaz ^v^ on 3/1/2024 in #help
Trying to pass a variable in .having()
@solo here is the function with my query, i tried passing
interval
as a 3 and 3 days but both of them results in an error.
intervalDays is not an array.
My use case is i just want to use the same query but with different interval, eg: 3 days, 7 days, 10 days8 replies
DTDrizzle Team
•Created by Kaz ^v^ on 3/1/2024 in #help
Trying to pass a variable in .having()
export async function getExpiringUserSubscriptionsAtInterval(
interval: number,
) {
const db = getDatabase(process.env.DATABASE_URL!);
return await db
.select({
userId: users.id,
subEnd: sql<Date>
MAX(${userSubscriptionDetails.endingAt}),
})
.from(users)
.innerJoin(
userSubscriptionDetails,
and(
eq(users.id, userSubscriptionDetails.userId),
isNull(userSubscriptionDetails.type),
),
)
.groupBy(
users.id
)
.having(({ endAt }) =>
sqldate_trunc('day', ${subEndAt}) = CURRENT_DATE + INTERVAL '${sql${interval} days'},
);
}
8 replies