umami/queries/analytics/pageview/getPageviewParams.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

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
});
}
async function relationalQuery(websiteId, start_at, end_at, column, table, filters = {}) {
2022-08-28 06:38:35 +02:00
const { parseFilters, rawQuery } = prisma;
const params = [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}
2022-10-12 04:37:38 +02:00
where website.website_uuid='${websiteId}'
and ${table}.created_at between $1 and $2
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.'));
}