mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
fix order by and revert getDateSQL
This commit is contained in:
parent
8500669ed0
commit
004ccdc22f
@ -19,6 +19,14 @@ const MYSQL_DATE_FORMATS = {
|
||||
year: '%Y-01-01T00:00:00Z',
|
||||
};
|
||||
|
||||
const POSTGRESQL_DATE_FORMATS = {
|
||||
minute: 'YYYY-MM-DD HH24:MI:00',
|
||||
hour: 'YYYY-MM-DD HH24:00:00',
|
||||
day: 'YYYY-MM-DD',
|
||||
month: 'YYYY-MM-01',
|
||||
year: 'YYYY-01-01',
|
||||
};
|
||||
|
||||
function getAddIntervalQuery(field: string, interval: string): string {
|
||||
const db = getDatabaseType();
|
||||
|
||||
@ -60,18 +68,16 @@ function getDateSQL(field: string, unit: string, timezone?: string): string {
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
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 `to_char(date_trunc('${unit}', ${field}), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
if (timezone) {
|
||||
const tz = moment.tz(timezone).format('Z');
|
||||
|
||||
return `date_format(convert_tz(${field},'+00:00','${tz}'), '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
return `date_format(${field}, '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
and event_type = {{eventType}}
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
|
@ -24,6 +24,7 @@ async function relationalQuery(
|
||||
createdAt: { gte: startDate, lte: endDate },
|
||||
},
|
||||
take: 500,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
and event_type = {{eventType}}
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user