implement filtering and cohorts to all relevant queries

This commit is contained in:
Francis Cao 2025-08-19 15:26:41 -07:00
parent 789b8b36d8
commit 2f1f704728
34 changed files with 311 additions and 167 deletions

View file

@ -14,9 +14,12 @@ export async function getWebsiteSessionsWeekly(
}
async function relationalQuery(websiteId: string, filters: QueryFilters) {
const { timezone = 'utc' } = filters;
const timezone = 'utc';
const { rawQuery, getDateWeeklySQL, parseFilters } = prisma;
const { queryParams } = parseFilters(filters);
const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({
...filters,
websiteId,
});
return rawQuery(
`
@ -24,8 +27,11 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
${getDateWeeklySQL('created_at', timezone)} as time,
count(distinct session_id) as value
from website_event
${cohortQuery}
${joinSessionQuery}
where website_id = {{websiteId::uuid}}
and created_at between {{startDate}} and {{endDate}}
${filterQuery}
group by time
order by 2
`,