Skip to content

Commit

Permalink
add timestamp column to prisma realtime queries
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscao633 committed Jun 20, 2024
1 parent 8a4fe95 commit 2969435
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
29 changes: 19 additions & 10 deletions src/queries/analytics/events/getEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ export function getEvents(...args: [websiteId: string, filters: QueryFilters]) {
function relationalQuery(websiteId: string, filters: QueryFilters) {
const { startDate } = filters;

return prisma.client.websiteEvent.findMany({
where: {
websiteId,
createdAt: {
gte: startDate,
return prisma.client.websiteEvent
.findMany({
where: {
websiteId,
createdAt: {
gte: startDate,
},
},
},
orderBy: {
createdAt: 'desc',
},
});
orderBy: {
createdAt: 'desc',
},
})
.then(a => {
return Object.values(a).map(a => {
return {
...a,
timestamp: new Date(a.createdAt).getTime() / 1000,
};
});
});
}

function clickhouseQuery(websiteId: string, filters: QueryFilters) {
Expand Down
29 changes: 19 additions & 10 deletions src/queries/analytics/sessions/getSessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ export async function getSessions(...args: [websiteId: string, filters: QueryFil
async function relationalQuery(websiteId: string, filters: QueryFilters) {
const { startDate } = filters;

return prisma.client.session.findMany({
where: {
websiteId,
createdAt: {
gte: startDate,
return prisma.client.session
.findMany({
where: {
websiteId,
createdAt: {
gte: startDate,
},
},
},
orderBy: {
createdAt: 'desc',
},
});
orderBy: {
createdAt: 'desc',
},
})
.then(a => {
return Object.values(a).map(a => {
return {
...a,
timestamp: new Date(a.createdAt).getTime() / 1000,
};
});
});
}

async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
Expand Down

0 comments on commit 2969435

Please sign in to comment.