2022-08-28 06:38:35 +02:00
|
|
|
import prisma from 'lib/prisma';
|
|
|
|
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
2022-07-21 23:57:29 +02:00
|
|
|
|
2022-07-23 04:50:43 +02:00
|
|
|
export async function getPageviewParams(...args) {
|
2022-08-28 06:38:35 +02:00
|
|
|
return runQuery({
|
|
|
|
[PRISMA]: () => relationalQuery(...args),
|
2022-07-25 18:47:11 +02:00
|
|
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
2022-07-23 04:50:43 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-10 22:42:18 +02:00
|
|
|
async function relationalQuery(websiteId, start_at, end_at, column, table, filters = {}) {
|
2023-01-19 00:09:49 +01:00
|
|
|
const { parseFilters, rawQuery, toUuid } = prisma;
|
|
|
|
const params = [websiteId, start_at, end_at];
|
2022-07-21 23:57:29 +02:00
|
|
|
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
|
|
|
table,
|
|
|
|
column,
|
|
|
|
filters,
|
|
|
|
params,
|
|
|
|
);
|
|
|
|
|
|
|
|
return rawQuery(
|
2022-08-28 06:38:35 +02:00
|
|
|
`select url x,
|
2022-08-08 10:26:20 +02:00
|
|
|
count(*) y
|
|
|
|
from ${table}
|
2022-10-12 04:37:38 +02:00
|
|
|
${` join website on ${table}.website_id = website.website_id`}
|
2022-08-08 10:26:20 +02:00
|
|
|
${joinSession}
|
2023-01-19 00:09:49 +01:00
|
|
|
where website.website_uuid = $1${toUuid()}
|
|
|
|
and ${table}.created_at between $2 and $3
|
2022-08-08 10:26:20 +02:00
|
|
|
and ${table}.url like '%?%'
|
|
|
|
${pageviewQuery}
|
|
|
|
${joinSession && sessionQuery}
|
|
|
|
${eventQuery}
|
|
|
|
group by 1
|
2022-08-28 06:38:35 +02:00
|
|
|
order by 2 desc`,
|
2022-07-21 23:57:29 +02:00
|
|
|
params,
|
|
|
|
);
|
|
|
|
}
|
2022-07-23 04:50:43 +02:00
|
|
|
|
|
|
|
function clickhouseQuery() {
|
|
|
|
return Promise.reject(new Error('Not implemented.'));
|
|
|
|
}
|