umami/queries/analytics/events/getEventUsage.ts

31 lines
779 B
TypeScript
Raw Normal View History

2023-05-04 02:17:57 +02:00
import clickhouse from 'lib/clickhouse';
2023-07-25 08:06:16 +02:00
import { CLICKHOUSE, PRISMA, runQuery, notImplemented } from 'lib/db';
2023-05-04 02:17:57 +02:00
export function getEventUsage(...args: [websiteIds: string[], startDate: Date, endDate: Date]) {
return runQuery({
2023-07-25 08:06:16 +02:00
[PRISMA]: notImplemented,
2023-05-04 02:17:57 +02:00
[CLICKHOUSE]: () => clickhouseQuery(...args),
});
}
function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) {
const { rawQuery } = clickhouse;
return rawQuery(
2023-07-25 08:06:16 +02:00
`
select
website_id as websiteId,
count(*) as count
2023-05-04 02:17:57 +02:00
from website_event
2023-07-25 08:06:16 +02:00
where website_id in {websiteIds:Array(UUID)}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
group by website_id
`,
2023-05-04 02:17:57 +02:00
{
websiteIds,
startDate,
endDate,
},
);
}