Enum mapped values in typedSQL
Hi! 👋
I’m having trouble using enums with mapped values in typedSql. Here’s what I have:
And in SQL:
Prisma sends
['away', 'appearOffline']
instead of ['away', 'appear_offline']
, which doesn’t match the DB values.
Prisma version: 6.3.1
Is this expected? Or am I missing something?
Thanks!1 Reply
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
Yes, this is a known issue with Prisma. When using
@map
directives on enum values, Prisma doesn't use the mapped values in raw SQL queries. Instead, it uses the enum identifiers (like 'appearOffline') rather than the database values ('appear_offline').
This behavior has been reported in several GitHub issues, including Enum values do not map to underlying raw values and Use @map'ed enum values as TS enum values.
The problem occurs because Prisma generates TypeScript enums with the original identifiers as values, not the mapped values:
Instead of what you might expect:
Workaround
A workaround mentioned in the issues is to access the internal mapping through Prisma's DMMF (Data Model Meta Format):
Then you could use this function to map your enum values before using them in raw SQL:
This issue has been open for quite some time, and there are ongoing discussions about how to address it without introducing breaking changes.
I hope this helps clarify the situation!
✅ Great, thanks for letting us know that this solved your question!