Export enums as const too, like Prisma
Closed this issue ยท 5 comments
Hi! Awesome work on this library, thanks for the time and effort!
When switching over from everything Prisma to Kysely, and generating the types with this library, I noticed the enums are not exported like Prisma does. The enum types are only exported as a type
, and not include a const
export like Prisma does.
So, for example if I have this defined in my schema.prisma
:
enum Language {
NL
EN
}
Prisma generated:
export const Language: {
NL: 'NL',
EN: 'EN',
};
export type Language = (typeof Language)[keyof typeof Language];
Which I could then use in some zod validation schema:
const schema = z.object({
language: z.nativeEnum(Language),
});
However, prisma-kysely
only generates the type, which I cannot use in zod anymore:
export type Language = 'NL' | 'EN';
So I was wondering if we could have a similar export of enums when using prisma-kysely
?
For now i'm using the exports from @prisma/client
, but I would like to ditch that and use all the types generated by prisma-kysely
.
Oh I hadn't thought of the zod use case. That sounds interesting. I'll give implementation a shot!
@valtyr awesome!
Also, I think i've found the code how Prisma does it, here: https://github.com/prisma/prisma/blob/ccf3df016e80fe72ba567f54a9c669ce2b926c9a/packages/client/src/generation/TSClient/Enum.ts#L36
@jvandenaardweg Try out snapshot 0.0.0-snapshot-20230428143338
and let me know if it fits the bill :)
@valtyr YES! This works perfectly, all the const
's are now there ๐
@jvandenaardweg Awesome! ๐ช ๐ฅณ๐ฏ This'll be part of the next release.