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]: drizzle-zod type doesn't return z.ZodDate for dataType date #3740

Closed
1 task done
ryuudotgg opened this issue Dec 11, 2024 · 5 comments
Closed
1 task done

[BUG]: drizzle-zod type doesn't return z.ZodDate for dataType date #3740

ryuudotgg opened this issue Dec 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@ryuudotgg
Copy link

ryuudotgg commented Dec 11, 2024

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.38.0

What version of drizzle-kit are you using?

0.30.0

Other packages

[email protected]

Describe the Bug

export const table = mysqlTable(
  "table",
  {
    createdAt: timestamp("created_at", { mode: "date", fsp: 3 })
      .notNull()
      .defaultNow(),
  },
);

export const schema = createInsertSchema(table);

In the example above, the returned type for createdAt is z.ZodString instead of z.ZodDate, regardless of the dataType.

I should mention that everything is correct during runtime, the issue is only in the types.

It used to work in [email protected]

@MickL
Copy link

MickL commented Dec 11, 2024

I think this is correct, isnt it? I dont know exactly about MySQL but I know for example that in PostgreSQL a number will always be a string because this is the most accurate way to save decimals. I imagine a timestamp will also return a string and not an actual date object.

@ryuudotgg
Copy link
Author

You're partially correct, it is stored as a string in the database, however the mode here is date, not string, which means Drizzle ORM will parse it as a JS Date.

You can also see this being done in the exact same way during runtime: column.ts#L92

@MickL

@L-Mario564
Copy link
Collaborator

@nemanjastanic Can you provide the full definition for the table alongside exactly how you've defined the schema? Unable to reproduce with the sample code you provided.

@ryuudotgg
Copy link
Author

Hey @L-Mario564, I just retried this, it seems it's caused by #3732. I missed this previously because I managed to suppress the error by adding .partial({}).

Please feel free to close this issue if you want to consider it a duplicate!

@L-Mario564
Copy link
Collaborator

@nemanjastanic Will close this in favor of the one you mentioned. Thanks.

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