disable object mapping for queryRaw
Is it possible to disable object mapping for returns of queryRaw? I just need the SQL result string for a fringe use case. I can't use JSON.stringify(), because the result can contain types that can't be serialized with it.
1 Reply
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
Prisma does not provide a switch to “turn off” the result mapping for
$queryRaw / $queryRawUnsafe. Raw queries always go through Prisma’s type mapping layer, which converts database values to JavaScript types like Date, BigInt, Decimal, Uint8Array, etc., just like normal Client queries.[Raw query mapping]
There is also no supported way to plug in a custom mapper for raw queries – this was explicitly confirmed in an official answer: Prisma always maps DateTime to Date and does not let you intercept or change that behavior on a per‑query basis.[Mapper discussion]
So, with the current APIs:
- You cannot disable object/value mapping for $queryRaw.
- You must work with the mapped JS values (including non‑JSON‑serializable ones like BigInt, Decimal, etc.), or post‑process them yourself (e.g. convert to strings).
If you truly need the raw wire format or a driver that doesn’t do this mapping, Prisma’s docs don’t describe any official escape hatch for $queryRaw; you’d need to use another SQL client or driver alongside Prisma for that fringe use case.
✅ Great, thanks for letting us know that this solved your question!