mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 05:37:20 +01:00
Events table.
This commit is contained in:
parent
a19248d713
commit
5e9299be1e
13 changed files with 131 additions and 31 deletions
|
|
@ -35,5 +35,6 @@ export default prisma;
|
|||
export async function runQuery(query) {
|
||||
return query.catch(e => {
|
||||
console.error(e);
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,5 +124,5 @@ export const countryFilter = data =>
|
|||
|
||||
export const percentFilter = data => {
|
||||
const total = data.reduce((n, { y }) => n + y, 0);
|
||||
return data.map(({ x, y }) => ({ x, y, z: total ? (y / total) * 100 : 0 }));
|
||||
return data.map(({ x, y, ...props }) => ({ x, y, z: total ? (y / total) * 100 : 0, ...props }));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -400,3 +400,41 @@ export function getActiveVisitors(website_id) {
|
|||
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
export function getEvents(website_id, start_at, end_at) {
|
||||
const db = getDatabase();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
select distinct event_type w, event_value x, count(*) y
|
||||
from event
|
||||
where website_id=$1
|
||||
and created_at between $2 and $3
|
||||
group by 1, 2
|
||||
order by 3 desc
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
);
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
select distinct event_type w, event_value x, count(*) y
|
||||
from event
|
||||
where website_id=?
|
||||
and created_at between ? and ?
|
||||
group by 1, 2
|
||||
order by 3 desc
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue