Open dmythro opened 2 months ago
You can use the second parameter refine
of createInsertSchema
function to specify your json structure once.
Something like createInsertSchema(someTable, { field1: z.array(z.string()) })
Hope this helps!
You can use the second parameter
refine
ofcreateInsertSchema
function to specify your json structure once.Something like
createInsertSchema(someTable, { field1: z.array(z.string()) })
Hope this helps!
Thanks, but it doesn't help. I don't wanna specify same schema twice. The whole purpose of this is to generate Zod schema from the actual table schema, which is defined in a single place and all changes later are done in a one place as well without duplicating them for validation.
What version of
drizzle-orm
are you using?0.33.0
What version of
drizzle-kit
are you using?0.24.2
Describe the Bug
When I create a JSON field like this
field1: json('field1').$type<string[]>().notNull().default([])
and create a Zod schema from that table withcreateInsertSchema()
, I get errors on data types when I parse the schema intoparams
from a request to insert it with Drizzle.Example:
I get typing errors which breaks the build and I have to manually cast the proper type inferred from the table schema again. And same happens with custom types as well. Removing
.partial()
doesn't really affect the result.Expected behavior
I expect JSON data types are properly inferred from the schema definition. Maybe I misuse something? I suppose there should also be something like
createUpdateSchema
maybe?Environment & setup
"drizzle-zod": "0.5.1".