All queries should use runQuery.

This commit is contained in:
Mike Cao 2020-09-02 15:14:33 -07:00
parent a3e920d944
commit f17be19110

View File

@ -252,7 +252,8 @@ 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",
@ -272,11 +273,13 @@ export function getMetrics(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",
@ -296,6 +299,7 @@ export function getMetrics(website_id, start_at, end_at) {
website_id,
start_at,
end_at,
),
);
}
@ -313,7 +317,8 @@ 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
@ -326,11 +331,13 @@ export function getPageviews(
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
@ -343,6 +350,7 @@ export function getPageviews(
website_id,
start_at,
end_at,
),
);
}
@ -355,7 +363,8 @@ 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}
@ -368,11 +377,13 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {
website_id,
start_at,
end_at,
),
);
}
if (db === MYSQL) {
return prisma.$queryRaw(
return runQuery(
prisma.$queryRaw(
`
select distinct ${type} x, count(*) y
from ${table}
@ -385,6 +396,7 @@ export function getRankings(website_id, start_at, end_at, type, table, domain) {
website_id,
start_at,
end_at,
),
);
}
@ -396,7 +408,8 @@ 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
@ -405,11 +418,13 @@ export function getActiveVisitors(website_id) {
`,
website_id,
date,
),
);
}
if (db === MYSQL) {
return prisma.$queryRaw(
return runQuery(
prisma.$queryRaw(
`
select count(distinct session_id) x
from pageview
@ -418,6 +433,7 @@ export function getActiveVisitors(website_id) {
`,
website_id,
date,
),
);
}
@ -428,7 +444,8 @@ 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,
@ -443,11 +460,13 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =
website_id,
start_at,
end_at,
),
);
}
if (db === MYSQL) {
return prisma.$queryRaw(
return runQuery(
prisma.$queryRaw(
`
select
event_value x,
@ -462,6 +481,7 @@ export function getEvents(website_id, start_at, end_at, timezone = 'utc', unit =
website_id,
start_at,
end_at,
),
);
}