Open hmh6a opened 1 month ago
I don't have any issues with filtering, for your example, does gte(tables.visits.createdAt, new Date())
work?
I am getting the same error, TypeError: value.getTime is not a function
, but only when updating. Here is my database schema.
createdDate: integer("created_date", { mode: "timestamp" })
.default(sql`(unixepoch())`)
.notNull(),
updatedDate: integer("updated_date", { mode: "timestamp" })
.$onUpdate(() => sql`(unixepoch())`)
.notNull(),
I suspect there is some epoch time vs JS date type issue. .$onUpdate(() => new Date())
works and so does setting it when updating with updatedDate: sql
(unixepoch())``. It is just odd that it doesn't work in the schema onUpdate function.
@magicalpuffin
You should change type from integer into text My problem solved like this
@magicalpuffin I've got the same issue. I was happy to see that they added onUpdate
but after refactoring to take advantage of it, I realized it didn't work on timestamps so I'm back to manually pushing updateOn
values until it gets fixed.
I also don't want a text column, because it's a timestamp, not text.
Hopefully we see a fix soon, this one's really annoying.
I did find what seems to be a way to do it. As long as you're okay with epoch time.
export const tableName = sqliteTable("tablename", {
id: ...,
updated_at: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdateFn(() => new Date()).$type<Date>(),
otherFields: ...
}
I've only tested this with SQLite, but it seems to be working for me.
What version of
drizzle-orm
are you using?0.30.10
What version of
drizzle-kit
are you using?0.21.2
Describe the Bug
Bug Report: Error when using time-related queries
Description
When attempting to use time-related queries with
drizzle-kit
, I encounter an error. Specifically, the error occurs when trying to fetch records from thevisits
table where thecreatedAt
timestamp is greater than or equal to the current time.Code Snippets
Here is the code that produces the error:
Schema definition for the
visits
table:Error Message
Expected behavior
No response
Environment & setup
No response