-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate enum casting helper functions (extensions) from prisma enums #95
Comments
Hey! I don't think I've ever come across this issue if I'm totally honest. But I'd totally be willing to consider a pull request that provides a clear example and an implementation 😄 |
Using kysely for the first time and ran into this same issue. Very possible I'm doing something incorrectly but seems that raw Prisma Enums cannot be used in SQL without an explicit cast. My example... This query: await prisma.$kysely.deleteFrom("SomeTable")
.where("relatedEntityType", "=", EntityType.User)
.execute(); Causes this error at runtime:
Changing this query to: await prisma.$kysely.deleteFrom("SomeTable")
.where("relatedEntityType", "=", sql<EntityType>`${EntityType.User}::"EntityType"`)
.execute(); Works just fine but is verbose and means we have to be super vigilant about not using enums directly. Is there a better way? I'd be happy to contribute a PR if what @luap2703 suggests is the best path forward. |
Indeed, same here. Another common use case is relying on the DB to generate UUID for It means, each time you want to filter a query by await prisma.$kysely.selectFrom("MyTable").where("id", "=", sql`${entityId}::uuid` |
Hey guys, I feel like this issue isn't directly related to prisma-kysely. It probably belongs in the https://github.com/eoin-obrien/prisma-extension-kysely repo (which uses prisma-kysely under the hood). The prisma-kysely package only really relates to generating Kysely schema definitions from Prisma schemas, and as of right now doesn't at all touch runtime code. Helpers and such should probably be suggested on the prisma-extension-kysely repo. Thanks :D |
Thanks for the great library!
The biggest drawback we currently face using kysely, this extension, postgresql and prisma is, that it is required to wrap every Postgresql enum before inserting/filtering. If we forget to do so, the query throws.
As this article shows, it is quite easy to add extensions to kysely by for example wrapping a sql tag around a variable to cast something.
Like this: sql
${ProductStatus.ARCHIVED}::product_status
,Wouldn't it be super helpful if a set of helper functions would directly be generated based on the Prisma schema's enums?
We are currently building these wrappers manually which is prone to erros, especially when renaming an enum.
The text was updated successfully, but these errors were encountered: