Reverted getDateQuery logic.

pull/1324/head
Mike Cao 2022-07-21 13:21:33 -07:00
parent 358c725828
commit 250cdce306
3 changed files with 6 additions and 18 deletions

View File

@ -14,24 +14,12 @@ export function getDatabase() {
return type; return type;
} }
export function getDateStringQuery(data, unit) {
const db = getDatabase();
if (db === POSTGRESQL) {
return `to_char(${data}, '${POSTGRESQL_DATE_FORMATS[unit]}')`;
}
if (db === MYSQL) {
return `DATE_FORMAT(${data}, '${MYSQL_DATE_FORMATS[unit]}')`;
}
}
export function getDateQuery(field, unit, timezone) { export function getDateQuery(field, unit, timezone) {
const db = getDatabase(); const db = getDatabase();
if (db === POSTGRESQL) { if (db === POSTGRESQL) {
if (timezone) { if (timezone) {
return `date_trunc('${unit}', ${field} at time zone '${timezone}')`; return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}'), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
} }
return `date_trunc('${unit}', ${field})`; return `date_trunc('${unit}', ${field})`;
} }
@ -40,7 +28,7 @@ export function getDateQuery(field, unit, timezone) {
if (timezone) { if (timezone) {
const tz = moment.tz(timezone).format('Z'); const tz = moment.tz(timezone).format('Z');
return `convert_tz(${field},'+00:00','${tz}')`; return `date_format(convert_tz(${field},'+00:00','${tz}', '${MYSQL_DATE_FORMATS[unit]}')`;
} }
return `${field}`; return `${field}`;

View File

@ -1,4 +1,4 @@
import { getDateQuery, getDateStringQuery, getFilterQuery, rawQuery } from 'lib/queries'; import { getDateQuery, getFilterQuery, rawQuery } from 'lib/queries';
export function getEventMetrics( export function getEventMetrics(
website_id, website_id,
@ -14,7 +14,7 @@ export function getEventMetrics(
` `
select select
event_value x, event_value x,
${getDateStringQuery(getDateQuery('created_at', unit, timezone), unit)} t, ${getDateQuery('created_at', unit, timezone)} t,
count(*) y count(*) y
from event from event
where website_id=$1 where website_id=$1

View File

@ -1,4 +1,4 @@
import { parseFilters, rawQuery, getDateQuery, getDateStringQuery } from 'lib/queries'; import { parseFilters, rawQuery, getDateQuery } from 'lib/queries';
export function getPageviewStats( export function getPageviewStats(
website_id, website_id,
@ -20,7 +20,7 @@ export function getPageviewStats(
return rawQuery( return rawQuery(
` `
select select
${getDateStringQuery('g.t', unit)} as t, g.t as t,
g.y as y g.y as y
from from
(select ${getDateQuery('pageview.created_at', unit, timezone)} t, (select ${getDateQuery('pageview.created_at', unit, timezone)} t,