mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 09:05:36 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
0b9987d9e9
2 changed files with 35 additions and 4 deletions
|
|
@ -35,6 +35,30 @@ function getAddMinutesQuery(field: string, minutes: number): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDayDiffQuery(field1: string, field2: string): string {
|
||||||
|
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||||
|
|
||||||
|
if (db === POSTGRESQL) {
|
||||||
|
return `${field1}::date - ${field2}::date`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db === MYSQL) {
|
||||||
|
return `DATEDIFF(${field1}, ${field2})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCastColumnQuery(field: string, type: string): string {
|
||||||
|
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||||
|
|
||||||
|
if (db === POSTGRESQL) {
|
||||||
|
return `${field}::${type}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db === MYSQL) {
|
||||||
|
return `${field}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getDateQuery(field: string, unit: string, timezone?: string): string {
|
function getDateQuery(field: string, unit: string, timezone?: string): string {
|
||||||
const db = getDatabaseType();
|
const db = getDatabaseType();
|
||||||
|
|
||||||
|
|
@ -193,6 +217,8 @@ function getSearchMode(): { mode?: Prisma.QueryMode } {
|
||||||
export default {
|
export default {
|
||||||
...prisma,
|
...prisma,
|
||||||
getAddMinutesQuery,
|
getAddMinutesQuery,
|
||||||
|
getDayDiffQuery,
|
||||||
|
getCastColumnQuery,
|
||||||
getDateQuery,
|
getDateQuery,
|
||||||
getTimestampIntervalQuery,
|
getTimestampIntervalQuery,
|
||||||
getFilterQuery,
|
getFilterQuery,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ async function relationalQuery(
|
||||||
}[]
|
}[]
|
||||||
> {
|
> {
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
const { getDateQuery, rawQuery } = prisma;
|
const { getDateQuery, getDayDiffQuery, getCastColumnQuery, rawQuery } = prisma;
|
||||||
const timezone = 'utc';
|
const timezone = 'utc';
|
||||||
const unit = 'day';
|
const unit = 'day';
|
||||||
|
|
||||||
|
|
@ -49,7 +49,10 @@ async function relationalQuery(
|
||||||
user_activities AS (
|
user_activities AS (
|
||||||
select distinct
|
select distinct
|
||||||
w.session_id,
|
w.session_id,
|
||||||
(${getDateQuery('created_at', unit, timezone)}::date - c.cohort_date::date) as day_number
|
${getDayDiffQuery(
|
||||||
|
getDateQuery('created_at', unit, timezone),
|
||||||
|
'c.cohort_date',
|
||||||
|
)} as day_number
|
||||||
from website_event w
|
from website_event w
|
||||||
join cohort_items c
|
join cohort_items c
|
||||||
on w.session_id = c.session_id
|
on w.session_id = c.session_id
|
||||||
|
|
@ -78,7 +81,7 @@ async function relationalQuery(
|
||||||
c.day_number as day,
|
c.day_number as day,
|
||||||
s.visitors,
|
s.visitors,
|
||||||
c.visitors as "returnVisitors",
|
c.visitors as "returnVisitors",
|
||||||
c.visitors::float * 100 / s.visitors as percentage
|
${getCastColumnQuery('c.visitors', 'float')} * 100 / s.visitors as percentage
|
||||||
from cohort_date c
|
from cohort_date c
|
||||||
join cohort_size s
|
join cohort_size s
|
||||||
on c.cohort_date = s.cohort_date
|
on c.cohort_date = s.cohort_date
|
||||||
|
|
@ -89,7 +92,9 @@ async function relationalQuery(
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
},
|
},
|
||||||
);
|
).then(results => {
|
||||||
|
return results.map(i => ({ ...i, percentage: Number(i.percentage) || 0 }));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clickhouseQuery(
|
async function clickhouseQuery(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue