Re-write CH queries to use query params.

This commit is contained in:
Brian Cao 2023-01-12 12:06:25 -08:00
parent 9a7385e4d5
commit befc5cf6c0
12 changed files with 114 additions and 125 deletions

View file

@ -28,14 +28,14 @@ async function relationalQuery(websiteId: string) {
}
async function clickhouseQuery(websiteId: string) {
const { rawQuery, getDateFormat } = clickhouse;
const params = [websiteId];
const { rawQuery } = clickhouse;
const params = { websiteId, startAt: subMinutes(new Date(), 5) };
return rawQuery(
`select count(distinct session_id) x
from event
where website_id = $1
and created_at >= ${getDateFormat(subMinutes(new Date(), 5))}`,
where website_id = {websiteId:UUID}
and created_at >= {startAt:DateTime('UTC')}`,
params,
);
}