Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: value.getTime is not a function #2323

Open
hmh6a opened this issue May 15, 2024 · 3 comments
Open

[BUG]: value.getTime is not a function #2323

hmh6a opened this issue May 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@hmh6a
Copy link

hmh6a commented May 15, 2024

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 the visits table where the createdAt timestamp is greater than or equal to the current time.

Code Snippets

Here is the code that produces the error:

const visits = await db.query.visits.findMany({
    where: gte(tables.visits.createdAt, Date.now()),
})

Schema definition for the visits table:

export const visits = sqliteTable('visits', {
    id: integer('id').primaryKey({ autoIncrement: true }),
    // ....
    createdAt: integer('created_at', { mode: 'timestamp' }).notNull().default(new Date().getTime()),
})

Error Message

Error: value.getTime is not a function

Expected behavior

No response

Environment & setup

No response

@hmh6a hmh6a added the bug Something isn't working label May 15, 2024
@magicalpuffin
Copy link

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.

@hmh6a
Copy link
Author

hmh6a commented May 27, 2024

@magicalpuffin

You should change type from integer into text
My problem solved like this

@bruceharrison1984
Copy link

bruceharrison1984 commented May 31, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants