mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
move queries
This commit is contained in:
parent
910f165103
commit
8aec6d7406
53 changed files with 920 additions and 485 deletions
28
queries/analytics/event/getEventMetrics.js
Normal file
28
queries/analytics/event/getEventMetrics.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { getDateQuery, getFilterQuery, rawQuery } from 'queries';
|
||||
|
||||
export function getEventMetrics(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
filters = {},
|
||||
) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
event_value x,
|
||||
${getDateQuery('created_at', unit, timezone)} t,
|
||||
count(*) y
|
||||
from event
|
||||
where website_id=$1
|
||||
and created_at between $2 and $3
|
||||
${getFilterQuery('event', filters, params)}
|
||||
group by 1, 2
|
||||
order by 2
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
19
queries/analytics/event/getEvents.js
Normal file
19
queries/analytics/event/getEvents.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { runQuery } from 'queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getEvents(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.event.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
17
queries/analytics/event/saveEvent.js
Normal file
17
queries/analytics/event/saveEvent.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { runQuery } from 'queries';
|
||||
import prisma from 'lib/db';
|
||||
import { URL_LENGTH } from 'lib/constants';
|
||||
|
||||
export async function saveEvent(website_id, session_id, url, event_type, event_value) {
|
||||
return runQuery(
|
||||
prisma.event.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
event_type: event_type?.substr(0, 50),
|
||||
event_value: event_value?.substr(0, 50),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue