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

[FEATURE]: drizzle-zod "push" refinements isntead of resetting #2248

Open
juliusmarminge opened this issue May 2, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@juliusmarminge
Copy link

juliusmarminge commented May 2, 2024

Describe what you want

by default, drizzle-zod handles max column length if the config.length field is set.

but when i add a refinement on that field, the length is no longer respected.

// example table
export const table = mysqlTable(
  "table",
  {
    id: varchar("id", { length: 36 }).primaryKey(),
    url: varchar("url", { length: 2048 }).notNull(),
  },
  (table) => ({ }),
);

// default schema
export const tableSchema = createInsertSchema(table);
tableSchema.parse({ id, url: "https://domain.com/some-super-long-path..." }); // fails cause string is too long

// restrict valid urls
export const tableSchema = createInsertSchema(table, {
  url: z.string().url(), // we now lost the `.max()` restriction that was auto-inferred by drizzle
});
tableSchema.parse({ id, url: "https://domain.com/some-super-long-string..." }); // now succeeds cause no more auto-inferred max length

would be nice to have some way to merge refinements, so I don't have to "manage" the length in 2 places

export const table = mysqlTable(
  "table",
  {
    id: varchar("id", { length: 36 }).primaryKey(),
    url: varchar("url", { length: 2048 }).notNull(), // <-- here
  },
  (table) => ({ }),
);
export const tableSchema = createInsertSchema(table, {
  url: z.string().url().max(2048), // <-- and here
});
@juliusmarminge juliusmarminge added the enhancement New feature or request label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant