umami/queries/analytics/eventData/getEventDataUsage.ts

31 lines
780 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 getEventDataUsage(...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 event_data
where created_at between {startDate:DateTime64} and {endDate:DateTime64}
2023-07-25 08:06:16 +02:00
and website_id in {websiteIds:Array(UUID)}
group by website_id
`,
2023-05-04 02:17:57 +02:00
{
websiteIds,
startDate,
endDate,
},
);
}