Skip to content

Commit

Permalink
update activityTable queries
Browse files Browse the repository at this point in the history
  • Loading branch information
xerosanyam committed Jun 27, 2024
1 parent 5235077 commit bb4633d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/db/tables/card.table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from '$lib/db/turso.db';
import { cardTable, type SelectCard } from '$lib/db/turso.schema';
import { activityTable, cardTable, type SelectCard } from '$lib/db/turso.schema';
import type { Difficulty } from '$lib/schemas';
import { and, count, desc, eq, lt, sql, } from 'drizzle-orm';

Expand Down Expand Up @@ -37,14 +37,14 @@ export const getCardsOrderByCreated = async (userId: string) => {

export const getCardsGroupedByCreated = async (userId: string) => {
console.time('getCardsGroupedByCreated')
const data = await db.select({ date: sql`DATE(${cardTable.createdAt}, 'unixepoch')`, count: count() }).from(cardTable).where(eq(cardTable.userId, userId)).groupBy(sql`DATE(${cardTable.createdAt}, 'unixepoch')`)
const data = await db.select({ date: sql`DATE(${activityTable.createdAt}, 'unixepoch')`, count: count() }).from(activityTable).where(and(eq(activityTable.userId, userId), eq(activityTable.action, 'INSERT'))).groupBy(sql`DATE(${activityTable.createdAt}, 'unixepoch')`)
console.timeEnd('getCardsGroupedByCreated')
return data
}

export const getCardsGroupedByUpdated = async (userId: string) => {
console.time('getCardsGroupedByCreated')
const data = await db.select({ date: sql`DATE(${cardTable.updatedAt}, 'unixepoch')`, count: count() }).from(cardTable).where(eq(cardTable.userId, userId)).groupBy(sql`DATE(${cardTable.updatedAt}, 'unixepoch')`)
const data = await db.select({ date: sql`DATE(${activityTable.createdAt}, 'unixepoch')`, count: count() }).from(activityTable).where(and(eq(activityTable.userId, userId), eq(activityTable.action, 'UPDATE'))).groupBy(sql`DATE(${activityTable.createdAt}, 'unixepoch')`)
console.timeEnd('getCardsGroupedByCreated')
return data
}
Expand Down

0 comments on commit bb4633d

Please sign in to comment.