Watched your video recently, and when you were explaining how to set up a sqlite schema for Drizzle, you mentioned that sqlite doesn’t have a built-in method for getting an epoch timestamp, which sounded off to me because I was doing just that literally a couple of days ago.
sqlite actually does have a built-in way to get the epoch time, with the only caveat being that it returns epoch seconds, not milliseconds.
This is documented in both the official sqlite docs and the Drizzle docs, so I’m not really sure why you’d use
export const tasks = sqliteTable("tasks", {
...,
updatedAt: integer("updated_at", { mode: "timestamp" })
.$defaultFn(() => new Date())
.$onUpdate(() => new Date()),
});
instead of
export const tasks = sqliteTable("tasks", {
...,
updatedAt: integer("updated_at", { mode: "timestamp" })
.default(sql`(unixepoch() * 1000)`)
.$onUpdate(() => sql`(unitepoch() * 1000)`),
});
Thanks for your videos in general and for this one in particular, keep on keeping on!
Watched your video recently, and when you were explaining how to set up a sqlite schema for Drizzle, you mentioned that sqlite doesn’t have a built-in method for getting an epoch timestamp, which sounded off to me because I was doing just that literally a couple of days ago.
sqlite actually does have a built-in way to get the epoch time, with the only caveat being that it returns epoch seconds, not milliseconds.
This is documented in both the official sqlite docs and the Drizzle docs, so I’m not really sure why you’d use
instead of
Thanks for your videos in general and for this one in particular, keep on keeping on!