mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
All queries should use runQuery.
This commit is contained in:
parent
a3e920d944
commit
f17be19110
116
lib/queries.js
116
lib/queries.js
@ -252,8 +252,9 @@ export function getMetrics(website_id, start_at, end_at) {
|
||||
const db = getDatabase();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select sum(t.c) as "pageviews",
|
||||
count(distinct t.session_id) as "uniques",
|
||||
sum(case when t.c = 1 then 1 else 0 end) as "bounces",
|
||||
@ -269,15 +270,17 @@ export function getMetrics(website_id, start_at, end_at) {
|
||||
group by 1, 2
|
||||
) t
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select sum(t.c) as "pageviews",
|
||||
count(distinct t.session_id) as "uniques",
|
||||
sum(case when t.c = 1 then 1 else 0 end) as "bounces",
|
||||
@ -293,9 +296,10 @@ export function getMetrics(website_id, start_at, end_at) {
|
||||
group by 1, 2
|
||||
) t
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -313,8 +317,9 @@ export function getPageviews(
|
||||
const db = getDatabase();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select ${getDateQuery(db, 'created_at', unit, timezone)} t,
|
||||
count(${count}) y
|
||||
from pageview
|
||||
@ -323,15 +328,17 @@ export function getPageviews(
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select ${getDateQuery(db, 'created_at', unit, timezone)} t,
|
||||
count(${count}) y
|
||||
from pageview
|
||||
@ -340,9 +347,10 @@ export function getPageviews(
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -355,8 +363,9 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {
|
||||
const filter = domain ? `and ${type} not like '%${domain}%'` : '';
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select distinct ${type} x, count(*) y
|
||||
from ${table}
|
||||
where website_id=$1
|
||||
@ -365,15 +374,17 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select distinct ${type} x, count(*) y
|
||||
from ${table}
|
||||
where website_id=?
|
||||
@ -382,9 +393,10 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -396,28 +408,32 @@ export function getActiveVisitors(website_id) {
|
||||
const date = subMinutes(new Date(), 5);
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select count(distinct session_id) x
|
||||
from pageview
|
||||
where website_id=$1
|
||||
and created_at >= $2
|
||||
`,
|
||||
website_id,
|
||||
date,
|
||||
website_id,
|
||||
date,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select count(distinct session_id) x
|
||||
from pageview
|
||||
where website_id=?
|
||||
and created_at >= ?
|
||||
`,
|
||||
website_id,
|
||||
date,
|
||||
website_id,
|
||||
date,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -428,8 +444,9 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =
|
||||
const db = getDatabase();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select
|
||||
event_value x,
|
||||
${getDateQuery(db, 'created_at', unit, timezone)} t,
|
||||
@ -440,15 +457,17 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =
|
||||
group by 1, 2
|
||||
order by 2
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return prisma.$queryRaw(
|
||||
`
|
||||
return runQuery(
|
||||
prisma.$queryRaw(
|
||||
`
|
||||
select
|
||||
event_value x,
|
||||
${getDateQuery(db, 'created_at', unit, timezone)} t,
|
||||
@ -459,9 +478,10 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =
|
||||
group by 1, 2
|
||||
order by 2
|
||||
`,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user