From 2d69b3087fa79712980508c5b6d4ab82a0c8c953 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Tue, 18 Aug 2020 18:33:59 -0700 Subject: [PATCH] Fix MySQL query. --- lib/queries.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/queries.js b/lib/queries.js index 387520f2..03b4759f 100644 --- a/lib/queries.js +++ b/lib/queries.js @@ -369,14 +369,34 @@ export function getRankings(website_id, start_at, end_at, type, table) { } export function getActiveVisitors(website_id) { - return prisma.$queryRaw( - ` + const db = getDatabase(); + const date = subMinutes(new Date(), 5); + + if (db === POSTGRESQL) { + return prisma.$queryRaw( + ` select count(distinct session_id) x from pageview where website_id=$1 and created_at >= $2 `, - website_id, - subMinutes(new Date(), 5), - ); + website_id, + date, + ); + } + + if (db === MYSQL) { + return prisma.$queryRaw( + ` + select count(distinct session_id) x + from pageview + where website_id=? + and created_at >= ? + `, + website_id, + date, + ); + } + + return Promise.resolve([]); }