TypedSQL and case
I need to create a TypedSQL query but it doesn't seem to be able to read case. Do I need to
@map
all of the parts of the model to snake_case?4 Replies
You chose to compile with the bot. One moment while I piece together your answer…
When using TypedSQL with Prisma, the generated result types from your SQL queries will use the column names as they exist in your database (e.g., snake_case), not the mapped field names from your Prisma schema (e.g., camelCase). Prisma does not automatically translate between these in TypedSQL. This means if your database uses snake_case and your Prisma schema uses camelCase with @map, the TypedSQL result types will still use the original snake_case names.
If you want your TypedSQL result types to match your Prisma model's camelCase field names, you would need to manually alias the columns in your SQL query, like so:
There is currently no built-in way for Prisma to automatically map all fields for you in TypedSQL. You do not need to add @map to your schema just for TypedSQL—@map is for mapping your Prisma model fields to the database columns, but TypedSQL will always reflect the actual database column names in its result types unless you alias them in your query. This is a known limitation and has been discussed as a possible area for future improvement, but for now, manual aliasing is required if you want camelCase in your TypedSQL result types Model and field inference in TypedSql queries.
Error: P1014
The underlying table for model
invoice
does not exist.🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
I got that error because the table is Invoice
I can
@@map
that to invoice but having to manually map those to snake_case is going to be a pain