Extracting literal values from Drizzle enums
I'm trying to make a zod enum schema from the values of a Drizzle enum I've created. I've looked through several other posts trying to do the same thing and it's unclear to me how to do this, particularly for
mysqlEnum
. The most promising way came from inspecting the enums at runtime. I found that I could access the values, just as I wanted, at myEnum.config.enumValues
. The only problem is that Typescript declares config protected and I get type errors.4 Replies
Do you want the enum as a type, as a ZodType or as a runtime value?
I’d be curious to know how to do all of the above though I was specifically asking about creating a zod schema you parse with.
For mysql it's a little easier than pg.
I have a couple enums in my tables and I declare them outside the table like this:
^ That's how you get the runtime value and the type
You can see here how to get the ZodType: https://orm.drizzle.team/docs/zod
Usage - DrizzleORM
Drizzle ORM | %s