umami/queries/analytics/pageview/getPageviewParams.js

41 lines
1019 B
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
});
}
2022-08-08 10:26:20 +02:00
async function relationalQuery(website_id, start_at, end_at, column, table, filters = {}) {
2022-08-28 06:38:35 +02:00
const { parseFilters, rawQuery } = prisma;
2022-08-08 10:26:20 +02:00
const params = [website_id, 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}
${joinSession}
where ${table}.website_id=$1
and ${table}.created_at between $2 and $3
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.'));
}