mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
922c3acab3
* Fix share URL permissions. * Add sql param logic. * Add permissions to edit website. * Update permissions. * Move parameters to param injection. * Sanitize eventdata. * Remove caret. * Fix avg.
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import prisma from 'lib/prisma';
|
|
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
|
|
|
export async function getPageviewParams(...args) {
|
|
return runQuery({
|
|
[PRISMA]: () => relationalQuery(...args),
|
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
|
});
|
|
}
|
|
|
|
async function relationalQuery(websiteId, start_at, end_at, column, table, filters = {}) {
|
|
const { parseFilters, rawQuery, toUuid } = prisma;
|
|
const params = [websiteId, start_at, end_at];
|
|
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
|
table,
|
|
column,
|
|
filters,
|
|
params,
|
|
);
|
|
|
|
return rawQuery(
|
|
`select url x,
|
|
count(*) y
|
|
from ${table}
|
|
${` join website on ${table}.website_id = website.website_id`}
|
|
${joinSession}
|
|
where website.website_uuid = $1${toUuid()}
|
|
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.'));
|
|
}
|