P
Prisma2w ago
Uncle

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
Prisma AI Help
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:
SELECT
id,
display_id AS "displayId",
created_at AS "createdAt"
FROM users
WHERE id = $1;
SELECT
id,
display_id AS "displayId",
created_at AS "createdAt"
FROM users
WHERE id = $1;
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.
Uncle
UncleOP2w ago
Error: P1014 The underlying table for model invoice does not exist.
Prisma AI Help
🤔 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.
Uncle
UncleOP2w ago
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

Did you find this page helpful?