drizzle-team / drizzle-team/drizzle-orm

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

Open
#2,248 0 comments 2 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.