Selecting DATE_TRUNC returns string but types as Date

Hi,
I have an issue that drizzle types the return type of due as Date, even though they are strings.

I boiled it down to the DATE_TRUNC function (and grouping by it) to cause the database to return strings instead,
if I just select and group by cardSchedules.due I actually get Date objects back.

Since DATE_TRUNC is supposed to return TIMESTAMP, I'm confused as to why drizzle still gives me strings.
Is there a way how I can select and group by the "hour" of a timestamp but still full Date objects back?


The code:
return db
    .select({
        count: count(),
        due: sql<Date>`DATE_TRUNC('hour', ${cardSchedules.due})`,
    })
    .from(cards)
    .innerJoin(cardSchedules, eq(cardSchedules.cardId, cards.id))
    .innerJoin(decks, eq(cards.deckId, decks.id))
    .where(
        and(
            eq(cards.userId, userId),
            eq(decks.enabledForReview, true),
            gte(cardSchedules.due, startHour),
            lt(cardSchedules.due, endHour),
        ),
    )
    .groupBy(sql`DATE_TRUNC('hour', ${cardSchedules.due})`)
    .orderBy(sql`DATE_TRUNC('hour', ${cardSchedules.due})`);


schema:
due: timestamp("due", { withTimezone: true, mode: "date" }).notNull(),
Was this page helpful?