Re-write CH queries to use query params.

This commit is contained in:
Brian Cao 2023-01-12 00:02:12 -08:00
parent b4bd988e4e
commit 1eb9e10d94
12 changed files with 81 additions and 100 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,
);
}