How do I use NOW() in Drizzle?

Can someone explain how to write the following query in Drizzle?
UPDATE users
SET datetime_last_login = NOW()
WHERE id = $1
UPDATE users
SET datetime_last_login = NOW()
WHERE id = $1
3 Replies
Angelelz
Angelelz13mo ago
The sql operator to the rescue:
db.update(users).set({datetimeLastLogin: sql`NOW()` }).where(eq(users.id, 1))
db.update(users).set({datetimeLastLogin: sql`NOW()` }).where(eq(users.id, 1))
Zamiel
ZamielOP13mo ago
Thank you very much! Is this worth adding to the docs? I feel like using NOW() must be pretty common for people using Postgres. Additionally, I did actually come across the docs talking about sql, but it wasn't clear that you can use it inside of a .set call. The only example talks about using it to replace the entire query with SQL using db.execute.
Angelelz
Angelelz13mo ago
I guess you could add an issue in GH to add that to the docs
Want results from more Discord servers?
Add your server