umami/queries/analytics/pageview/getPageviewParams.js

41 lines
1,019 B
JavaScript
Raw Normal View History

2022-08-28 04:38:35 +00:00
import prisma from 'lib/prisma';
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
2022-07-21 21:57:29 +00:00
2022-07-23 02:50:43 +00:00
export async function getPageviewParams(...args) {
2022-08-28 04:38:35 +00:00
return runQuery({
[PRISMA]: () => relationalQuery(...args),
2022-07-25 16:47:11 +00:00
[CLICKHOUSE]: () => clickhouseQuery(...args),
2022-07-23 02:50:43 +00:00
});
}
2022-08-08 08:26:20 +00:00
async function relationalQuery(website_id, start_at, end_at, column, table, filters = {}) {
2022-08-28 04:38:35 +00:00
const { parseFilters, rawQuery } = prisma;
2022-08-08 08:26:20 +00:00
const params = [website_id, start_at, end_at];
2022-07-21 21:57:29 +00:00
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
table,
column,
filters,
params,
);
return rawQuery(
2022-08-28 04:38:35 +00:00
`select url x,
2022-08-08 08:26:20 +00: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 04:38:35 +00:00
order by 2 desc`,
2022-07-21 21:57:29 +00:00
params,
);
}
2022-07-23 02:50:43 +00:00
function clickhouseQuery() {
return Promise.reject(new Error('Not implemented.'));
}