MySql NOW() in Drizzle
Hi! I might be struggling because this is hard to search for, but I'm wondering if it's possible to use mysql's
NOW()
function with Drizzle, rather than creating a new ts Date object and using that? Not that it matters much, but it would be good to keep everything in the db layer if possible. Apologies if I've missed this, I searched here, the reference docs site, and some READMEs on GitHub.8 Replies
Hi! Sure, it's possible. We have
.defaultNow()
on timestamps for MySQL -> column: timestamp("column_name").defaultNow()
But we will deprecate it soon in a favour of CURRENT_TIMESTAMP
which seems to work in the same way and also compitable in all environments
so I would suggest to use this pattern after a column you want to have it
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_current-timestampFor example PlanetScale(https://planetscale.com/) works not well with
now()
but workds good with CURRENT_TIMESTAMP
That's for setting the default in the table definition right? Rather than in for example a select or insert query? I guess I could use sql
CURRENT_TIMESTAMP
) as the value in an insert into?yes, that's for setting the default in the table definition, which will make current column optional on inserts
and then database will populate it for you
Yes - I mean if I want to use CURRENT_TIMESTAMP in a query or an insert I can do so with
right?
(sorry, formatting isn't great)
yes, you can use it
not sure about inserts
need to check it
Ok, I'll give it a go. Thanks! Just wanted to make sure I wasn't missing a dsl method for that.