© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•10mo ago•
2 replies
hyperknot

SQLite auto-update timestamp

I'm trying to auto-update timestamp when using SQLite.

This is my try, but it doesn't work:

    createdAt: integer('created_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),

    updatedAt: integer('updated_at', { mode: 'timestamp' })
      .notNull()
      .default(sql`(unixepoch())`)
      .$onUpdateFn(() => sql`(unixepoch())`),
    createdAt: integer('created_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),

    updatedAt: integer('updated_at', { mode: 'timestamp' })
      .notNull()
      .default(sql`(unixepoch())`)
      .$onUpdateFn(() => sql`(unixepoch())`),


Can you tell me how to make it work? The createdAt one works correctly.

updatedAt gives:

Error occurred in handler for ...: Error: value.getTime is not a function
    at Worker.<anonymous>     at Worker.emit (node:events:518:28)
    at MessagePort.<anonymous> (node:internal/worker:268:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
Error occurred in handler for ...: Error: value.getTime is not a function
    at Worker.<anonymous>     at Worker.emit (node:events:518:28)
    at MessagePort.<anonymous> (node:internal/worker:268:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Auto update timestamp fields
Drizzle TeamDTDrizzle Team / help
3y ago
SQLite: timestamp vs timestamp_ms modes
Drizzle TeamDTDrizzle Team / help
3y ago
Issue with CURRENT_TIMESTAMP bun:sqlite
Drizzle TeamDTDrizzle Team / help
2y ago
Auto delete record using timestamp
Drizzle TeamDTDrizzle Team / help
3y ago