Closed markkkkas closed 9 months ago
I've also tried to dig into createInsertSchema
code and noticed that if the column is instance of *CustomColumn
, then it's instantly set to z.any()
. Can i rely on some properties from those classes to build different zod type or it requires some bigger refactoring?
check this out - https://discord.com/channels/1043890932593987624/1114275121851535431
@dankochetov Thanks for reply. Again this is not very convenient way to always specify the zod type. From DX side - i believe this should be done by create*Schema
helper.
this actually forbids me from using drizzle
Could customType
's param maybe leverage an optional schema
or validation
property?
check this out - https://discord.com/channels/1043890932593987624/1114275121851535431
This comment solved this issue. Feel free to create another ticket with feature request on how to improve the DX for this particular part
@AndriiSherman I have implemented customNumberType<>()
, customStringType<>()
and customDateType<>()
which mirror customType<>()
but utilise additional ColumnDataType
s.
Specifically, I have added 'customNumber' | 'customString' | 'customDate'
to ColumnDataType
:
https://github.com/drizzle-team/drizzle-orm/blob/15ff6b49bff580b8f07077a044be4cb52ec17183/drizzle-orm/src/column-builder.ts#L9-L18
These ColumnDataType
s are then picked up in drizzle-zod
to build the correct types in the Zod schema. This allows custom types to push through to Zod schemas without the case-by-case refinement in your Discord suggestion.
Let me know what you think of the approach. I have done a limited implementation for MySQL to suit immediate needs but from what I can see it would extend to the other drivers relatively easily. Happy to work on a PR and/or share my current patches.
What version of
drizzle-orm
are you using?^0.26.1
What version of
drizzle-kit
are you using?^0.18.1
Describe the Bug
I need to use custom type, to support
nanoid
, its just a simple postgresvarchar
data type with fixed length.Lets assume this is my database table definition
When I'm creating a zod schema from my
positions
table I can see, thatid
was set toZodAny
.I believe i can workaround this with refining the
id
field, but i don't feel that i need to explicitly set the type again for schema.Expected behavior
id
is parsed as string to zod schema.Environment & setup
No response