drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: drizzle-zod "push" refinements isntead of resetting
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### 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.
```ts
// 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
```ts
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
});
```
Contributor guide
Assessment
This issue has not been assessed yet.