created_at/updated_at

Hello there, newbie here. I'm struggling with something fairly basic, does anyone know how can I have a created_at and updated_at working? Thanks!
2 Replies
turtles
turtlesOP10mo ago
I'm on postgres btw
Amruth Pillai
Amruth Pillai10mo ago
I use this:
createdAt: timestamp('created_at', { mode: "date", withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { mode: "date", withTimezone: true }).notNull().defaultNow(),
createdAt: timestamp('created_at', { mode: "date", withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { mode: "date", withTimezone: true }).notNull().defaultNow(),
Both values would be initialised to the current date. To set up updatedAt, the recommended method is to just set updatedAt: new Date() when you are updating a record.
Want results from more Discord servers?
Add your server