Limit the Amount of Returned Data with Prisma Client

Ryan Chenkie
InstructorRyan Chenkie
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

Prisma Client allows us to limit the amount of data that is returned from queries. It also allows us to be specific about which data should be included in the returned dataset. In this lesson, we use the select and include operators to be specific about the shape of our returned data.

Ryan Chenkie: [0:00] We can use Prisma to get back only a subset of the information that is contained within a table. For example, when we get back our reviews on the products, we may not want the id for the review or the productId. We might just want the text and the rating.

[0:14] In the include call, say that you want to get back only those two fields. Reviews becomes an object, in which we provide the select keyword. We say that text should be true and rating should be true as well. Save the endpoint and check it out in the browser.

[0:31] We can apply the same pattern to the base products model that we are querying for. If, for example, we wanted to get just the name and reviews, we can do so in the findMany call. To do so, we need the select keyword.

[0:45] Select and include cannot exist together at the root. In this case, we need to use just select. We can provide name: true to select, and then we can just take the reviews selection that we have already set up and put it up into the top level select. Then we get rid of include and save the endpoint to check it out in the browser.

Danilo Cabello
Danilo Cabello
~ 3 years ago

Hi Ryan, thank you for the course so far, content is great and flows nicely. Will new episodes be posted? Curious about validation and permissions (authorization).

Ryan Chenkie
Ryan Chenkieinstructor
~ 3 years ago

Thanks for checking it out!

I might post some more videos or perhaps do a more advanced set of tutorials. Anything else you'd be looking for in an advanced course?

Stephen
Stephen
~ 3 years ago

Would love to see topics about transactions, running raw queries, rolling back migrations, etc. And also, does Primsa allow me to create my own methods for a given model? Something like prima.product.findOne().hasReview()?

Ryan Chenkie
Ryan Chenkieinstructor
~ 3 years ago

Thanks for the feedback Stephen! I'll see if I can focus on those topics in my future lessons.

Devin Rhode
Devin Rhode
~ a year ago

Hey Ryan, this seemed to be the leading prisma source on the internet even after a year! Would love some more of these high quality videos!

Ryan Chenkie
Ryan Chenkieinstructor
~ a year ago

Hey Ryan, this seemed to be the leading prisma source on the internet even after a year! Would love some more of these high quality videos!

Thanks! More to come 👍

Markdown supported.
Become a member to join the discussionEnroll Today