P
Prisma2w ago
max

Is joining views into models a recommended pattern? 🦄

We're a bit on the edge with preview features but we just discovered today how convenient it is to create Views and be able to reference and include them from other Models. Underlying we're using Postgres for context. Simplified Schema:
previewFeatures = ["typedSql", "views", "relationJoins"]

Model Person{
id String
name String
workingTime WorkingTime
}

View WorkingTime {
personId String
targetHours Decimal
actualHours Decimal
}
previewFeatures = ["typedSql", "views", "relationJoins"]

Model Person{
id String
name String
workingTime WorkingTime
}

View WorkingTime {
personId String
targetHours Decimal
actualHours Decimal
}
Working time represents the amount of hours the employee has worked and should work. We actually have it as a parameterized view that can react on input via client-extentions but more on that in another thread There is much more going on in our schema but basically WorkingTime is a fairly complex View that Joins over many tables, It in itself is very performant. Is it a good practice to use this setup a lot wherever Views are the most fitting solution? Or are there downsides to this that we've not yet noticed? Its pretty sexy because we can include this from anywhere fully type-safe and don't have to use queryRawTyped to fetch WorkingTime separately and then always manually merge persons and their corresponding working time afterwards. Is this a good approach or are there downsides? This Question continues in another thread due to the question being technically unrelated and the character limit
2 Replies
Prisma AI Help
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Nurul
Nurul2w ago
I don't see any major downsides in this approach. The only one minor point would be that views can add complexity to your database schema. As your application evolves, you'll need to maintain both your base tables and your views. Besides this the view feature would move from preview feature to GA soon as mentioned here: https://github.com/prisma/prisma/discussions/26136 So, views will become more performant and stable in next few months 👍
GitHub
Preview Features Update 2025 · prisma prisma · Discussion #26136
Hi everybody, Over the past few years, we’ve introduced several preview features to expand the Prisma ORM's capabilities. Some have been well-received and integrated into the core, while others...

Did you find this page helpful?