aboutsummaryrefslogtreecommitdiff
path: root/src/queries/sql/sessions/getSessionData.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/queries/sql/sessions/getSessionData.ts
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'src/queries/sql/sessions/getSessionData.ts')
-rw-r--r--src/queries/sql/sessions/getSessionData.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/queries/sql/sessions/getSessionData.ts b/src/queries/sql/sessions/getSessionData.ts
new file mode 100644
index 0000000..8f1e493
--- /dev/null
+++ b/src/queries/sql/sessions/getSessionData.ts
@@ -0,0 +1,60 @@
+import clickhouse from '@/lib/clickhouse';
+import { CLICKHOUSE, PRISMA, runQuery } from '@/lib/db';
+import prisma from '@/lib/prisma';
+
+const FUNCTION_NAME = 'getSessionData';
+
+export async function getSessionData(...args: [websiteId: string, sessionId: string]) {
+ return runQuery({
+ [PRISMA]: () => relationalQuery(...args),
+ [CLICKHOUSE]: () => clickhouseQuery(...args),
+ });
+}
+
+async function relationalQuery(websiteId: string, sessionId: string) {
+ const { rawQuery } = prisma;
+
+ return rawQuery(
+ `
+ select
+ website_id as "websiteId",
+ session_id as "sessionId",
+ data_key as "dataKey",
+ data_type as "dataType",
+ replace(string_value, '.0000', '') as "stringValue",
+ number_value as "numberValue",
+ date_value as "dateValue",
+ created_at as "createdAt"
+ from session_data
+ where website_id = {{websiteId::uuid}}
+ and session_id = {{sessionId::uuid}}
+ order by data_key asc
+ `,
+ { websiteId, sessionId },
+ FUNCTION_NAME,
+ );
+}
+
+async function clickhouseQuery(websiteId: string, sessionId: string) {
+ const { rawQuery } = clickhouse;
+
+ return rawQuery(
+ `
+ select
+ website_id as websiteId,
+ session_id as sessionId,
+ data_key as dataKey,
+ data_type as dataType,
+ replace(string_value, '.0000', '') as stringValue,
+ number_value as numberValue,
+ date_value as dateValue,
+ created_at as createdAt
+ from session_data final
+ where website_id = {websiteId:UUID}
+ and session_id = {sessionId:UUID}
+ order by data_key asc
+ `,
+ { websiteId, sessionId },
+ FUNCTION_NAME,
+ );
+}