mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
convert analytics queries
This commit is contained in:
parent
4f12933f42
commit
6ea2282f82
12 changed files with 470 additions and 52 deletions
|
|
@ -1,6 +1,20 @@
|
|||
import { prisma, runQuery } from 'lib/db';
|
||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||
import {
|
||||
rawQueryClickhouse,
|
||||
getDateFormatClickhouse,
|
||||
prisma,
|
||||
runAnalyticsQuery,
|
||||
runQuery,
|
||||
} from 'lib/db';
|
||||
|
||||
export async function getEvents(websites, start_at) {
|
||||
export function getEvents(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
function relationalQuery(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.event.findMany({
|
||||
where: {
|
||||
|
|
@ -16,3 +30,20 @@ export async function getEvents(websites, start_at) {
|
|||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function clickhouseQuery(websites, start_at) {
|
||||
return rawQueryClickhouse(
|
||||
`
|
||||
select
|
||||
event_id,
|
||||
website_id,
|
||||
session_id,
|
||||
created_at,
|
||||
url,
|
||||
event_type
|
||||
from event
|
||||
where website_id in (${websites.join[',']}
|
||||
and created_at >= ${getDateFormatClickhouse(start_at)})
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue