Timestamp from Postgres returns date object despite schema using string mode?

Hello team, I'm confused if this is a bug because I haven't seen any other threads about it. When I define my timestamp columns like this:
effectiveDate: timestamp("effective_date", { withTimezone: true, mode: 'string' }).notNull(),
effectiveDate: timestamp("effective_date", { withTimezone: true, mode: 'string' }).notNull(),
How come the return type of the column when I fetch data says string, however when I log the value or use it anywhere, it's actually a JS date object? Is this a known issue?
10 Replies
Gavin
Gavin16mo ago
I am having the same issue with postgres: createdAt: timestamp('created_at', { mode: 'string', withTimezone: true, precision: 6 }) .defaultNow() .notNull(), updatedAt: timestamp('updated_at', { mode: 'string', withTimezone: true, precision: 6 }) .defaultNow() .notNull(), Type inference of return types says string, but it's actually a JS Date object, and some code elsewhere blows up.
DYELbrah
DYELbrahOP16mo ago
Yeah this is absolutely terrible, I don't understand how this isn't a bigger deal? How are people not running into this? @Gavin are you still having the same issue?
Angelelz
Angelelz16mo ago
GitHub
[BUG]: timestamp with mode string is returned as Date object instea...
What version of drizzle-orm are you using? 0.27.0 What version of drizzle-kit are you using? 0.19.2 Describe the Bug timestamps aren't being inferred as string Table Schema that we use export c...
Angelelz
Angelelz16mo ago
They provide a workaround there
DYELbrah
DYELbrahOP16mo ago
Damn I can't implement a workaround because my team creates migration files and use the Supabase CLI to handle migrations, then we just use drizzle kit introspect... wait nvm that workaround should work sweet, I thought we had to add a transformation to drizzle itself somewhere. Thanks
Gavin
Gavin15mo ago
@DYELbrah I would be, I just turned it to date mode and deal with converting back and forth 🤷‍♂️
tylerlantern
tylerlantern15mo ago
i got a problem
created_at: sql`${schema.chat_messages.created_at}`.as('chat_messages.created_at'),
created_at: sql`${schema.chat_messages.created_at}`.as('chat_messages.created_at'),
i can not get date type when i apply alias column from this column any idea
Blacklight
Blacklight15mo ago
I am also having this same issue ^^^
Angelelz
Angelelz15mo ago
When you use the sql operator you effectively lose the transformation drizzle does on your columns. A solution for this is use the mapWith() method on the sql operator
Blacklight
Blacklight15mo ago
I'm not using the sql operator when I get the issue
Want results from more Discord servers?
Add your server