mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
match cloud stats in self hosted
This commit is contained in:
parent
8a4623eb7b
commit
76a5ac8e46
3 changed files with 20 additions and 16 deletions
|
|
@ -23,15 +23,15 @@ const POSTGRESQL_DATE_FORMATS = {
|
|||
year: 'YYYY-01-01',
|
||||
};
|
||||
|
||||
function getAddMinutesQuery(field: string, minutes: number): string {
|
||||
function getAddIntervalQuery(field: string, interval: string): string {
|
||||
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return `${field} + interval '${minutes} minute'`;
|
||||
return `${field} + interval '${interval}'`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return `DATE_ADD(${field}, interval ${minutes} minute)`;
|
||||
return `DATE_ADD(${field}, interval ${interval})`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,15 +80,15 @@ function getDateQuery(field: string, unit: string, timezone?: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
function getTimestampIntervalQuery(field: string): string {
|
||||
function getTimestampDiffQuery(field1: string, field2: string): string {
|
||||
const db = getDatabaseType();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return `floor(extract(epoch from max(${field}) - min(${field})))`;
|
||||
return `floor(extract(epoch from (${field2} - ${field1})))`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return `floor(unix_timestamp(max(${field})) - unix_timestamp(min(${field})))`;
|
||||
return `timestampdiff(second, ${field1}, ${field2})`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -216,11 +216,11 @@ function getSearchMode(): { mode?: Prisma.QueryMode } {
|
|||
|
||||
export default {
|
||||
...prisma,
|
||||
getAddMinutesQuery,
|
||||
getAddIntervalQuery,
|
||||
getDayDiffQuery,
|
||||
getCastColumnQuery,
|
||||
getDateQuery,
|
||||
getTimestampIntervalQuery,
|
||||
getTimestampDiffQuery,
|
||||
getFilterQuery,
|
||||
parseFilters,
|
||||
getPageFilters,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue