Added parseDateRangeQuery function.

This commit is contained in:
Mike Cao 2023-07-26 09:55:54 -07:00
parent 09af33c77e
commit 1648707fc7
9 changed files with 48 additions and 80 deletions

View file

@ -2,26 +2,26 @@ import clickhouse from 'lib/clickhouse';
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
import prisma from 'lib/prisma';
export function getEvents(...args: [websiteId: string, startAt: Date, eventType: number]) {
export function getEvents(...args: [websiteId: string, startDate: Date, eventType: number]) {
return runQuery({
[PRISMA]: () => relationalQuery(...args),
[CLICKHOUSE]: () => clickhouseQuery(...args),
});
}
function relationalQuery(websiteId: string, startAt: Date, eventType: number) {
function relationalQuery(websiteId: string, startDate: Date, eventType: number) {
return prisma.client.websiteEvent.findMany({
where: {
websiteId,
eventType,
createdAt: {
gte: startAt,
gte: startDate,
},
},
});
}
function clickhouseQuery(websiteId: string, startAt: Date, eventType: number) {
function clickhouseQuery(websiteId: string, startDate: Date, eventType: number) {
const { rawQuery } = clickhouse;
return rawQuery(
@ -37,12 +37,12 @@ function clickhouseQuery(websiteId: string, startAt: Date, eventType: number) {
event_name as eventName
from website_event
where website_id = {websiteId:UUID}
and created_at >= {startAt:DateTime}
and created_at >= {startDate:DateTime}
and event_type = {eventType:UInt32}
`,
{
websiteId,
startAt,
startDate,
eventType,
},
);