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 generates ZodString type for numeric field #2353

Open
cellulosa opened this issue May 20, 2024 · 1 comment
Open

[BUG]: drizzle-zod generates ZodString type for numeric field #2353

cellulosa opened this issue May 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@cellulosa
Copy link

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

I defined a numeric field:

import { pgTable, text, timestamp, numeric } from 'drizzle-orm/pg-core';
import { createInsertSchema, createSelectSchema } from 'drizzle-zod';

export const user = pgTable('user', {
	id: text('id').primaryKey(),
	githubId: numeric('github_id').unique()
});

export const insertUserSchema = createInsertSchema(user);
export const selectUserSchema = createSelectSchema(user);

The types generated with createInsertSchema / createSelectSchema result in:

const insertUserSchema: ZodObject<{
    id: ZodString;
    githubId: ZodOptional<ZodNullable<ZodString>>;
},

therefore the parsing fails:

insertUserSchema.parse({
	id: generateId(15),
	githubId: 0123456789
})

Expected behavior

numeric() should be converted to ZodNumber

Environment & setup

drizzle-zod 0.5.1

@cellulosa cellulosa added the bug Something isn't working label May 20, 2024
@cellulosa cellulosa reopened this May 30, 2024
@cellulosa
Copy link
Author

for the moment this issue can be circumnavigated by overriding insertUserSchema:

export const insertUserSchema = createInsertSchema(user, {
	githubId: z.number()
});

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

1 participant