Default values to integer timestamps in sqlite

I would like to set a default timestamp on record create in mysql. My schema look like this: export const users = sqliteTable("user", { ... createdAt: integer("createdAt", { mode: "timestamp_ms" }) .default(new Date()) } Unfortunately this doesn`t work. Db push throws an error: "SqliteError: near "Aug": syntax error" Typescript is not accepting time as number. Can anybody help me to fill the proper value in default method?
1 Reply
francis
francis16mo ago
@jackaltd why not use NOW() in the database itself?
.default(sql`NOW()`)
.default(sql`NOW()`)
actually, this is SUPER bad and I don't think you want this what you are doing is defining a table that instead of defaulting the table column to the current time at the time the row is created, you are trying to default all rows to the time right now because new Date() runs on schema evaluation and will generate a migration containing the raw current date string, which will then apply to all created rows almost certainly NOT what you want to do
Want results from more Discord servers?
Add your server