-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for manually managing prepared statements #24171
Comments
Prisma actually uses prepared statements under the hood and also caches and reuses them. I hence renamed the issue a tiny bit to make this a request for "manually managing" prepared statements. |
If so, suppose if I have a conditional parameter like this
Is this handled by prisma caching mechanism? like which query to select form cache. |
Yes, when executing these different "paths" different queries are generated - and the correct prepared statement from the cache is used for each case. |
Alright, that's nice but still we need a manual prepared statement feature to optimize queries further and remove redundant overhead. Are contributors actively working on this? |
We at Prisma are not. |
Problem
Currently, Prisma ORM prepares queries dynamically each time a CRUD operation is performed on a table. This can result in unnecessary overhead, while in complex queries e.g. nesting relations and selecting fields, it can significantly reduce the performance. especially when the same query is executed multiple times with different values it does not make sense to build the query on each execution when only a few fixed parameters are changed.
Comparison with Existing Feature:
Drizzle ORM: drizzle-orm provides support for prepared statement which can be used to prebuild queries to use later with dynamic parameters. below snipped from the official docs.
Similar to prisma.$queryRaw, prepared statements offer the advantage of dynamic query execution. However, they provide 100% type safety just like prisma's ordinary table methods.
Suggested solution
Introduce support for prepared statements in Prisma ORM. Prepared statements act as pre-defined query templates that can be constructed once and reused with varying parameters. This approach can improve query performance and simplify code complexity.
For the above feature I expect a similar FluentApi to build a prepared statement or alternatively expected syntax can be :
The text was updated successfully, but these errors were encountered: