mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Unified loading states.
This commit is contained in:
parent
7b5591a3ce
commit
da8c7e99c5
52 changed files with 506 additions and 364 deletions
57
src/queries/sql/events/getEventData.ts
Normal file
57
src/queries/sql/events/getEventData.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { EventData } from '@/generated/prisma';
|
||||
import prisma from '@/lib/prisma';
|
||||
import clickhouse from '@/lib/clickhouse';
|
||||
import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
|
||||
|
||||
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 },
|
||||
);
|
||||
}
|
||||
|
||||
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 },
|
||||
);
|
||||
}
|
||||
|
|
@ -117,5 +117,5 @@ async function clickhouseQuery(
|
|||
`;
|
||||
}
|
||||
|
||||
return rawQuery(sql, params);
|
||||
return rawQuery(sql, params).then(result => result?.[0]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue