Prisma client - computed fields v2 #14793
Labels
kind/feature
A request for a new feature.
status/has-client-extension
This feature request is available as a Client Extension.
team/client
Issue for team Client.
topic: clientExtensions
topic: computed fields
topic: extend-client
Extending the Prisma Client
Problem
I often select user's firstName and lastName to just concat it or password to tell if user has it and then cut off from the rest of response
Suggested solution
Computed fields
For example i'll use this user model:
I want to have ability to extend prisma client, for example:
Then query this fields:
I expect the user object to have this fields:
Defined:
id
,firstName
,name
,hasPassword
Undefined (selected internally but not passed to result):
lastName
,password
Alternatives
This is the same aggregation as we saw before but it is not flexible and requires me to cut off some fields every time:
Additional context
Example implementation:
removeFalse(object)
function that removes all object fields withfalse
value, example:Before:
After:
present(result, query)
function that truncates query result to match select statement, example:Select statement (
query
argument):Before:
After (selects
firstName
andlastName
):Now we will use three layers of query:
presentation
- defines what user seessubquery
- adds fields todatabase
querydatabase
- selects all required fields from dbAssuming
presentation
query to be:We see two
subqueries
inpresentation
query:Let's build
database
query, execute it and save result asdbResult
:Warning: we should cut off all
false
select statements to make object joins correctlyNow call the subqueries callbacks like:
Concat subquery results with
dbResult
and save it asresult
:And return presented result:
We finally got:
Also it would be good to have support for nesting subqueries and async subquery callback
The text was updated successfully, but these errors were encountered: