mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 14:47:14 +01:00
add date param to values
This commit is contained in:
parent
c18daf4845
commit
88aa341821
3 changed files with 29 additions and 7 deletions
|
|
@ -2,14 +2,16 @@ import prisma from 'lib/prisma';
|
|||
import clickhouse from 'lib/clickhouse';
|
||||
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
|
||||
|
||||
export async function getValues(...args: [websiteId: string, column: string]) {
|
||||
export async function getValues(
|
||||
...args: [websiteId: string, column: string, startDate: Date, endDate: Date]
|
||||
) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(...args),
|
||||
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, column: string) {
|
||||
async function relationalQuery(websiteId: string, column: string, startDate: Date, endDate: Date) {
|
||||
const { rawQuery } = prisma;
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -19,12 +21,17 @@ async function relationalQuery(websiteId: string, column: string) {
|
|||
inner join session
|
||||
on session.session_id = website_event.session_id
|
||||
where website_event.website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
`,
|
||||
{ websiteId },
|
||||
{
|
||||
websiteId,
|
||||
startDate,
|
||||
endDate,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, column: string) {
|
||||
async function clickhouseQuery(websiteId: string, column: string, startDate: Date, endDate: Date) {
|
||||
const { rawQuery } = clickhouse;
|
||||
|
||||
return rawQuery(
|
||||
|
|
@ -32,7 +39,12 @@ async function clickhouseQuery(websiteId: string, column: string) {
|
|||
select distinct ${column} as value
|
||||
from website_event
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
`,
|
||||
{ websiteId },
|
||||
{
|
||||
websiteId,
|
||||
startDate,
|
||||
endDate,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue