Feedback: Reconsidering Limitations on SQL Views in Prisma 6.13 #27784
Closed
renatocron
announced in
Feedback
Replies: 1 comment
|
thanks! https://github.com/prisma/prisma/releases/tag/6.14.0 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Question
Hi Prisma Team & Community,
I'm opening this thread to discuss the recent changes in Prisma 6.13.0, specifically the restrictions introduced on SQL Views, including:
@id,@unique/@@unique, and@relationon viewsfindUnique, cursor-based pagination, implicit ordering, and relations involving views🚩 Why This Matters
In many real-world, complex applications, views aren't just "simple virtual tables." Instead, they're frequently critical for efficiently handling:
While Prisma's new limitations align closely with SQL semantics, they unintentionally eliminate practical, previously functional patterns crucial in sophisticated applications.
With the views, I was able to get prisma to build complex ACL-based filtering logic with dynamic permissions on the real tables, then only use the views for the projections.
If we had a way to convert from Prisma.Enumerable<Prisma.[Table]WhereInput> to SQL from prisma itself, we could theoretically at least use queryRaw and keep the builders with the type safety yet.
📌 Concrete Examples from Real Usage
Below are three real scenarios demonstrating these limitations clearly:
Example 1: Advanced Dashboard with Dynamic Filtering & Relations
Example 2: Permission-Based Dashboard Consolidation
Example 3: IoT Device Management with Complex Relationships
In IoT applications, views are essential for handling device relationships where multiple tables reference external system keys. For instance, detecting inactive devices across organizations:
This pattern enabled efficient querying of complex device states (active/inactive) while maintaining relationships to device metadata, firmware versions, and organizational data - all through a performant view that abstracted the underlying EXISTS/NOT EXISTS logic.
Crucially, passing WHERE conditions directly to the view allows the SQL query planner to push down predicates into the view definition, enabling optimizations like:
Without view relations, developers must either fetch all view results and filter in-memory (defeating the purpose of database optimization) or resort to complex manual SQL that loses type safety and Prisma's composability benefits.
Why TypedSQL Isn't a Complete Solution
While TypedSQL (introduced in v5.19.0) is excellent for static queries, it has significant limitations:
.sqlfiles that can't adapt to runtime conditionsgetVariavelGlobalWhereSet()patterns aboveTypedSQL works great for known, static queries, but cannot replicate the dynamic filtering and relational traversals that views + Prisma Client enabled.
🚧 Request for Reconsideration
I fully understand and appreciate Prisma's goal of aligning views with SQL semantics, but could we explore alternatives such as:
Option 1: Explicit Read-Only Relations
Option 2: Opt-In Advanced Mode
@@view.strict(false)) for advanced use cases or other keyword eg:model|view|relationed_viewOption 3: Ideas?
Conclusion
The recent Prisma 6.13 changes, while technically correct from a SQL perspective, inadvertently limit crucial real-world use cases that many teams rely on. This undermines Prisma's position as a versatile, developer-friendly ORM.
Views with relations and virtual relations enabled powerful patterns for:
The community needs a path forward that balances SQL correctness with practical usability. Perhaps there's a middle-ground solution we can collaboratively explore that preserves both semantic correctness and developer productivity.
I'd love to hear thoughts from both the Prisma team and the broader community. How are others handling these limitations? What migration strategies have worked?
Thanks for reading, and looking forward to a productive discussion!
All reactions