umami/queries/analytics/pageview/getPageviewParams.js
2022-08-08 01:26:20 -07:00

42 lines
1.0 KiB
JavaScript

import { parseFilters, rawQuery, runAnalyticsQuery } from 'lib/db';
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
export async function getPageviewParams(...args) {
return runAnalyticsQuery({
[RELATIONAL]: () => relationalQuery(...args),
[CLICKHOUSE]: () => clickhouseQuery(...args),
});
}
async function relationalQuery(website_id, start_at, end_at, column, table, filters = {}) {
const params = [website_id, start_at, end_at];
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
table,
column,
filters,
params,
);
return rawQuery(
`
select url x,
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
order by 2 desc
`,
params,
);
}
function clickhouseQuery() {
return Promise.reject(new Error('Not implemented.'));
}