update CH rawquery and type

This commit is contained in:
Francis Cao 2023-09-29 11:00:06 -07:00
parent 35d45334df
commit 98b7624e8f
17 changed files with 169 additions and 52 deletions

View file

@ -42,7 +42,10 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
);
}
async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
async function clickhouseQuery(
websiteId: string,
filters: QueryFilters,
): Promise<{ events: number; fields: number; records: number }> {
const { rawQuery, parseFilters } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, filters);
@ -59,11 +62,19 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
count(*) as "total"
from event_data
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime} and {endDate:DateTime}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
${filterQuery}
group by event_id, event_key
) as t
`,
params,
);
).then(a => {
return Object.values(a).map(a => {
return {
events: Number(a.events),
fields: Number(a.fields),
records: Number(a.records),
};
});
});
}