valtyr/prisma-kysely

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.

valtyr commented

Oh I hadn't thought of the zod use case. That sounds interesting. I'll give implementation a shot!

valtyr commented

@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 ๐Ÿ‘

valtyr commented

@jvandenaardweg Awesome! ๐Ÿช…๐Ÿฅณ๐Ÿ‘ฏ This'll be part of the next release.