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]: Cannot use schema.coerce on refining drizzle-zod types #3842

Open
1 task done
cybercoder-naj opened this issue Dec 25, 2024 · 0 comments
Open
1 task done

[BUG]: Cannot use schema.coerce on refining drizzle-zod types #3842

cybercoder-naj opened this issue Dec 25, 2024 · 0 comments
Labels
drizzle/zod enhancement New feature or request

Comments

@cybercoder-naj
Copy link

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

What version of drizzle-kit are you using?

0.30.1

Other packages

[email protected]

Describe the Bug

Consider the following schema below where the fields createdAt and pinUntil are timestamps and they translate to using the Date object from JavaScript:

export const announcements = pgTable('announcements', {
  id: serial('id').primaryKey(),
  title: text('title').notNull(),
  description: text('description').notNull(),
  createdAt: timestamp('created_at').notNull(),
  pinUntil: timestamp('pin_until')
});

/* Option 1 */
const insertAnnouncementSchema = createInsertSchema(announcements, {
  createdAt: z.coerce.date(),
  pinUntil:  z.coerce.date().optional(),
})

I cannot coerce the types in drizzle-zod and extend the existing zod types at the same time. For an API server that serializes the request body in a string format, I should be able to coerce the types.

@cybercoder-naj cybercoder-naj added the bug Something isn't working label Dec 25, 2024
@L-Mario564 L-Mario564 added enhancement New feature or request drizzle/zod and removed bug Something isn't working labels Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drizzle/zod enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants