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:
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
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.
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?
There is an open issue for this: https://github.com/drizzle-team/drizzle-orm/issues/806
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...
They provide a workaround there
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
@DYELbrah I would be, I just turned it to date mode and deal with converting back and forth 🤷♂️
i got a problem
i can not get date type when i apply alias column from this column any idea
I am also having this same issue ^^^
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 operatorI'm not using the
sql
operator when I get the issue