Schema to type
Hey guys, how do you make a schema item as a static type ?
for example, this thing:
as
14 Replies
There are several ways: https://orm.drizzle.team/docs/goodies#type-api
Goodies - DrizzleORM
Drizzle ORM | %s
bless you
so I made it, but have few questions about it:
for example in this code
You can't use the ifering helpers like that
You have to use the table itself
There are plenty of examples in the docs
oh, okay lol
i'll rtfm and stop annoying you
I can help, no problem, but so can the docs
yeah; but I didnt see something in the doc:
can you set custom messages if something is missing...
Like I did in my custom schema?
I don't understand the question, can you write an example?
and, like for example, with my useForm, values are string then I check the type with a transform
but in this case, with and insertProductSchema, it doesnt work
and like that:
If you're using zod, you might want to take a look at drizzle-zod
It's an extension to create zod schemas for validations, seems like it's exactly what you're looking for
In my case, I think i'll be forced to create a new schema
because, for example, my product take in attributes "price" which is a number,
but with the 'useForm' hook, you'r forced to take a string, then transform it to a number, then submit it
like that for example:
That's up to you how you want to handle your business logic. You can detach your front end logic from whatever you have in your backend by writing your own schema validators
But you could pull the schema from the db using drizzle-zod, end then transform it however you want for your application
zod has helpers for that