max
max
PPrisma
Created by max on 2/20/2025 in #help-and-questions
Parameterized Views for postgres 🦄
@Nurul (Prisma) I forgot to mention you, so you probably didn't receive a notification. Any input would be greatly appreciated
7 replies
PPrisma
Created by max on 2/20/2025 in #help-and-questions
Parameterized Views for postgres 🦄
If I simply extend the view in the schema by some made up property holder to make it appear in the type like to :
view PersonTime {
view_param_date_start DateTime?
// All regular colums that actually exist on the view
}
view PersonTime {
view_param_date_start DateTime?
// All regular colums that actually exist on the view
}
then of course we have type support for: include: {workingTime: {where: {view_param_date_start: "2025-01-01"}}} This actually works if I write an extension for $allOperations that - looks through the args, extracts all parameters that it finds that start with (defined by convention) "viewp_param_xyz", - deletes them from the args and and sets them as omit: {view_param_xyz}. - set the extracted params like in the Original pst via transaction. It has to be omitted or else prisma tries to find it in the View where it actually doesn't exist since we just faked it for type support. But its by all means not a clean solution.
7 replies
PPrisma
Created by max on 2/20/2025 in #help-and-questions
Parameterized Views for postgres 🦄
Thanks for the response. Do you have any input on how I could make the passing of the viewParams better? Currently we do
prisma.$extends(withParams({dateRangeStart})).person.findMany({include: {workingTime: true}).
prisma.$extends(withParams({dateRangeStart})).person.findMany({include: {workingTime: true}).
What would be the dream:
prisma.person.findMany(
{include: {workingTime: {viewParams: {dateRangeStart}}}
)
prisma.person.findMany(
{include: {workingTime: {viewParams: {dateRangeStart}}}
)
To make such an extension for one model would probably be somehow (if even at all?) possible to extend the type and react on its existence to set session variables like before, but as soon as we include from another path like account.person.workingTime, this wouldn't work anymore Is it somehow possible to extend a specific type like WorkingTimeWhereArgs? Cause if so then it would probably be possible generically and we'd just have to add another extension that looks through the entire args and if it finds a viewParams section it writes them to the session variables
7 replies