mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 21:27:20 +01:00
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { EventData } from '@/generated/prisma/client';
|
|
import prisma from '@/lib/prisma';
|
|
import clickhouse from '@/lib/clickhouse';
|
|
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
|
|
|
const FUNCTION_NAME = 'getEventData';
|
|
|
|
export async function getEventData(...args: [eventId: string]): Promise<EventData[]> {
|
|
return runQuery({
|
|
[PRISMA]: () => relationalQuery(...args),
|
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
|
});
|
|
}
|
|
|
|
async function relationalQuery(eventId: string) {
|
|
const { rawQuery } = prisma;
|
|
|
|
return rawQuery(
|
|
`
|
|
select website_id as websiteId,
|
|
session_id as sessionId,
|
|
event_id as eventId,
|
|
url_path as urlPath,
|
|
event_name as eventName,
|
|
data_key as dataKey,
|
|
string_value as stringValue,
|
|
number_value as numberValue,
|
|
date_value as dateValue,
|
|
data_type as dataType,
|
|
created_at as createdAt
|
|
from event_data
|
|
where event_id = {{eventId::uuid}}
|
|
`,
|
|
{ eventId },
|
|
FUNCTION_NAME,
|
|
);
|
|
}
|
|
|
|
async function clickhouseQuery(eventId: string): Promise<EventData[]> {
|
|
const { rawQuery } = clickhouse;
|
|
|
|
return rawQuery(
|
|
`
|
|
select website_id as websiteId,
|
|
session_id as sessionId,
|
|
event_id as eventId,
|
|
url_path as urlPath,
|
|
event_name as eventName,
|
|
data_key as dataKey,
|
|
string_value as stringValue,
|
|
number_value as numberValue,
|
|
date_value as dateValue,
|
|
data_type as dataType,
|
|
created_at as createdAt
|
|
from event_data
|
|
where event_id = {eventId:UUID}
|
|
`,
|
|
{ eventId },
|
|
FUNCTION_NAME,
|
|
);
|
|
}
|