2022-08-26 07:04:32 +02:00
|
|
|
import clickhouse from 'lib/clickhouse';
|
2022-08-29 19:47:01 +02:00
|
|
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
|
|
|
import prisma from 'lib/prisma';
|
2022-12-13 04:45:38 +01:00
|
|
|
import { Prisma } from '@prisma/client';
|
2022-07-12 23:14:36 +02:00
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
export async function getSession(args: { id: string }) {
|
2022-08-28 06:38:35 +02:00
|
|
|
return runQuery({
|
2022-12-13 04:45:38 +01:00
|
|
|
[PRISMA]: () => relationalQuery(args),
|
|
|
|
[CLICKHOUSE]: () => clickhouseQuery(args),
|
2022-07-21 06:31:26 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
async function relationalQuery(where: Prisma.SessionWhereUniqueInput) {
|
2022-11-08 01:22:49 +01:00
|
|
|
return prisma.client.session.findUnique({
|
|
|
|
where,
|
|
|
|
});
|
2022-07-12 23:14:36 +02:00
|
|
|
}
|
2022-07-21 06:31:26 +02:00
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
async function clickhouseQuery({ id: sessionId }: { id: string }) {
|
2022-08-28 06:38:35 +02:00
|
|
|
const { rawQuery, findFirst } = clickhouse;
|
2023-01-12 09:02:12 +01:00
|
|
|
const params = { sessionId };
|
2022-07-21 06:31:26 +02:00
|
|
|
|
2022-08-28 06:38:35 +02:00
|
|
|
return rawQuery(
|
2022-11-08 07:35:51 +01:00
|
|
|
`select
|
2022-10-12 08:09:06 +02:00
|
|
|
session_id,
|
2022-07-21 06:31:26 +02:00
|
|
|
website_id,
|
|
|
|
created_at,
|
|
|
|
hostname,
|
|
|
|
browser,
|
|
|
|
os,
|
|
|
|
device,
|
|
|
|
screen,
|
2022-08-28 06:38:35 +02:00
|
|
|
language,
|
2023-02-20 18:04:20 +01:00
|
|
|
country,
|
|
|
|
subdivision1,
|
|
|
|
subdivision2,
|
|
|
|
city
|
2023-03-29 20:06:12 +02:00
|
|
|
from website_event
|
2023-01-12 09:02:12 +01:00
|
|
|
where session_id = {sessionId:UUID}
|
2022-11-08 07:35:51 +01:00
|
|
|
limit 1`,
|
2022-08-28 06:38:35 +02:00
|
|
|
params,
|
2022-11-08 01:22:49 +01:00
|
|
|
).then(result => findFirst(result));
|
2022-07-21 06:31:26 +02:00
|
|
|
}
|