Refactored functionality for all time date range.

This commit is contained in:
Mike Cao 2023-07-26 13:42:55 -07:00
parent c3973f5fb5
commit d06808985b
11 changed files with 91 additions and 33 deletions

View file

@ -16,32 +16,36 @@ async function relationalQuery(websiteId: string) {
const { rawQuery } = prisma;
const website = await loadWebsite(websiteId);
return rawQuery(
const result = await rawQuery(
`
select
min(created_at) as min,
max(created_at) as max
min(created_at) as mindate,
max(created_at) as maxdate
from website_event
where website_id = {{websiteId::uuid}}
and created_at >= {{startDate}}
`,
{ websiteId, startDate: maxDate(new Date(DEFAULT_RESET_DATE), new Date(website.resetAt)) },
);
return result[0] ?? null;
}
async function clickhouseQuery(websiteId: string) {
const { rawQuery } = clickhouse;
const website = await loadWebsite(websiteId);
return rawQuery(
const result = await rawQuery(
`
select
min(created_at) as min,
max(created_at) as max
min(created_at) as mindate,
max(created_at) as maxdate
from website_event
where website_id = {websiteId:UUID}
and created_at >= {startDate:DateTime}
`,
{ websiteId, startDate: maxDate(new Date(DEFAULT_RESET_DATE), new Date(website.resetAt)) },
);
return result[0] ?? null;
}