Unified loading states.

This commit is contained in:
Mike Cao 2025-06-13 21:13:11 -07:00
parent 7b5591a3ce
commit da8c7e99c5
52 changed files with 506 additions and 364 deletions

View 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 },
);
}

View file

@ -117,5 +117,5 @@ async function clickhouseQuery(
`;
}
return rawQuery(sql, params);
return rawQuery(sql, params).then(result => result?.[0]);
}