Updating a date with the node-postgres adapter
I am trying to update a date value like this:
But I get an error
value.toISOString is not a function
, and searching that up, I came across this: https://github.com/drizzle-team/drizzle-orm/issues/2388
In the schema it is defined like this: completedDate: timestamp({ withTimezone: true }),
I am not really sure how to solve it, I'd prefer to solve it without using type: 'string', because there's other code depending on it being a Date object returned..
Am I doing something wrong or is it just broken?7 Replies
All the db drivers by default always returns strings for dates. You have to set the
mode
on you column to tell Drizzle how to handle it from there.even when setting mode: "date" I get the exact same error
Assuming you haven't had it set from the very beginning and you've seeded your db with some things already, maybe try dropping your db.
dropping the db won't help here, this isn't a sql datatype problem
check with a select to see what actual type you get out the other end, to make sure it's operating in date mode properly
Yeah it pruned my local db when I changed it so it should be fine
I get out a date if I'm querying it, and that date object has toISOString. This happens somewhere internally in drizzle
if you pass in the result of the query to an update, what happens?
that works fine apparently
but setting completedDate: queryResult.completedDate fails
I think I figured it out, I have a updatedAt that I forgot, that is exactly like what's in the issue I linked on the table 🙃
If I remove the $onUpdate it works, so I guess the date works, but I need to provide the old date from updatedAt...