IP
IP
DTDrizzle Team
Created by cvr on 7/4/2023 in #help
How to set a default timestamp_ms for sqlite
was just having the same issue, trying to insert a millesec-timestamp into integer("createdAt", {mode: "timestamp_ms" }) field. Had to use the createdAt: integer('created_at', { mode: 'timestamp_ms' }).$default(() => new Date()), which has a $default function (instead of the native sql function). It did work:
{
createdAt: 2024-01-02T16:52:53.621Z,
}
{
createdAt: 2024-01-02T16:52:53.621Z,
}
... but would have been nice to have a native solution. I did a lot of trial and error trying to get the unixepoch('subsec') to work, but it would just end up as a null at the end. Maybe because it was a float, and drizzle was expecting an int. This is the expression i used for the reference.
createdAt: integer('created_at', { mode: 'timestamp_ms' }).default(sql`(unixepoch('subsecond')*1000)`)
createdAt: integer('created_at', { mode: 'timestamp_ms' }).default(sql`(unixepoch('subsecond')*1000)`)
16 replies