Replies: 41 comments 86 replies
|
First of all, I love the feature! Raw SQL is a must for me, and this cleans up the code quite a bit. I have a few questions, though. Firstly, I did not see any mention of typedSQL with serverless in the documentation. I keep running into a "Runtime.ImportModuleError: Error: Cannot find module '.prisma/client/sql'" error in Lambda. Should the packaging be done differently somehow? Secondly, JSON values are inferred as JsonValue in TypedSQL with Postgres. For example, if I create a query like |
|
Hello Prisma team, I've encountered an issue while trying to use the new TypedSQL feature in a Next.js project with Prisma ORM. I've created a repository to demonstrate the problem: https://github.com/Gubiar/prisma-type-safe-sql Issue Description: Steps to Reproduce:
Additional Information:
Expected Behavior: Actual Behavior: Environment:
I've provided a minimal reproduction in the linked repository. Any insights or assistance in resolving this issue would be greatly appreciated. Thank you for your time and support! Keep up the fantastic work! Your efforts are making a real difference in the developer community. 👏 |
|
Two questions here:
I only want a
|
|
Is there a way to run without needing the database running? Currently, our CI/CD pipeline builds/deploys a docker image of our web service, and I would like to avoid having to start a postgres container and deploy a migration in CI to be able to package everything. |
|
How can I apply statement in For example: SELECT *
FROM users u
WHERE
u.role = $1I want to apply With SELECT *
FROM users u
WHERE
($1 IS NULL OR u.role = $1)But it gives |
|
Hey all 👋 I'm running prisma I definitely passed queries into all invocations of |
|
first of all, cool feature, I have severall feedbacks, so I would distribute them in multiple comments We can comment the params. But can we also create a comment that appears as TSDoc? (e.g. what the query is doing) |
|
One issue i found is that the properties of the result are marked as optional/nullable. Can I make them non-nullable? Maybe this is just a documentation issue and i am missing something. my query -- @param {String} $1:organisationId
WITH RECURSIVE parentOrganisation AS (
SELECT
id
FROM
"Organisation"
WHERE
id = $1
UNION
SELECT
childOrganisation.id
FROM
"Organisation" childOrganisation
INNER JOIN parentOrganisation po ON po.id = childOrganisation."parentOrganisationId"
)
SELECT * FROM parentOrganisation; |
|
one limitation is that the columns that are fetched are fixed, so we can't use Of course this is a tricky problem, but maybe there is a way to at least add some convenience to make the query less static. Also it would be cool to have some convenience to be able to use a normal prisma I mention this because with typedSQL you can partially work around some prisma limitations, like this issue #3725 (comment) but only partially, because in the above example you would of course want to use |
|
Thanks for TypedSQL! Really great to have more ways to connect TypeScript and SQL 🙌 I wanted to find out what the feedback would be on allowing TypedSQL for an alternate syntax for Prisma schema files. Would this be something that would be considered? Ideally I would like SQL-in-JS (eg. using |
|
Needing a db connection to generate with --sql definitely threw a wrench in my team's adoption of this feature... Spent >2 days trying to get it to work with our build system and had to tap out :( Really would like to use this but not feasible for us right now Some complications for us are that we currently don't commit our generated code, and we are using e.g. typegraphql-prisma generator which made committing our generated code more complicated. Being able to run this "offline" without a db connection would be amazing, but not sure of your implementation details/requirements so 🤷 |
|
I think there is a partial answer for this already in this discussion, but I'd like to raise it again. How can we deal with optional values for SQL statements? What we're doing right now is something like this: select
"field",
from
"Table"
where
"tenantId" = coalesce(${tenantId}, "tenantId")Where we pass in select
"field",
from
"Table"
where
"tenantId" = coalesce($1, "tenantId")Now the parameter has to be a I'd love for something like this: -- @param {String?} $1:tenantId
select
"field",
from
"Table"
where
"tenantId" = coalesce($1, "tenantId")Not the |
|
Hi, really liking this new feature 🎉 const boxofficePlatformFee = await locals.prisma.$queryRaw`SELECT SUM("price") AS "presaleOrdersPlatformFee"
FROM "Ticket" t
WHERE t.status NOT IN (${Prisma.join(INVALID_FINISHED_ORDER_STATUSES)})`;I tried SELECT SUM("price") AS "presaleOrdersPlatformFee"
FROM "Ticket" t
WHERE t.status NOT IN ($1)await locals.prisma.$queryRawTyped(calculatePrice(Prisma.join(INVALID_FINISHED_ORDER_STATUSES)))but I get |
|
For longer SQL queries WITH clauses would be beneficial to clean up the SQL. Currently it seems that WITH clauses throw Also, is there a way to utilise one SQL block in multiple different TypedSQL files without the need to duplicate it in each file? |
|
The TypedSQL queries I'm logging don't actually run in SQL. Following this documentation, I created select * from person where id = any ($1);Calling it with: await prisma.$queryRawTyped(repro([1, 2]));And logging the query with: Gives me: Attempting to run either of these in SQL is an error: select * from person where id = any (1,2)
select * from person where id = any ([1,2])Because it's expecting this: select * from person where id = any (array[1,2])Can logging the query log the actual SQL that's sent to the database? |
|
TL;DR It would be nice if we could name the We generally try to avoid uppercase letters in our filenames. However, if I try to generate the client with a file called Would be nice if Prisma automatically translated kebab case to camel case. Kinda like it does to snake case for migrations. :-) Such a cool feature! |
|
It is not possible to use the param in more than one place.
Invalid Raw query failed. Code: code: 'P2010', It worked:
|
|
I'm having an issue with the return type Result[] of queryRawTyped. I'm returning an array that includes a status of type "Unset" | "Approved" | null. In my typedSQL file, it is set as such: My query is defined like this: and the type like this: With this setup, I get the error: The only solution I found was this: or to add string to the type but that kind of defeats the purpose of the status field... Any ideas how I can directly typecast the the Result[] I receive from queryRawTyped without mapping over it afterwards?? |
|
Hi, first of all, thank you for this feature! |
|
An active DB connection to use the --sql flag makes use of this difficult in a CI pipeline. |
|
I'm also trying to upsert an unknown amount of rows in MySql. Is this possible without array support? |
|
Is there a way to use dynamic ORDER BY and LIMIT expressions with typedSql? ORDER BY $2 $3; ends up with ORDER BY $2;ends up with |
|
A quick update, we plan to release this preview feature to GA between September 2025 - February 2026. Read more here: #26136 |
|
It seems that the following error occurs when using placeholders with Does anyone know a solution to this? |
|
Awsome feature but it REALLY needs a way to define the import and export locations, because it breaks when using with multiclients (different databases each with it's own prisma schema and client) |
|
Quoting a user from Twitter:
|
|
TypedSQL is pretty great. 3 nits:
|
|
Copying my feedback from #27204 1. Crashing
|
|
Hi there, is anyone using PostgreSQL features like json_agg and json_build_object that wish it properly generated types for json? I've made an issue about it I hope Prisma implements types for it too: #27296 |
|
As far as I can see, it's not possible to combine TypeSql with views. Is that correct?
|

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
TypedSQL is a new feature of Prisma ORM which lets you write your raw SQL queries in a fully type-safe manner.
Please share your feedback about
typedSql(released in v5.19.0 of Prisma ORM) in this discussion.GA planned for September 2025 - February 2026
All reactions