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.
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?
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()?
Thanks for the feedback Stephen! I'll see if I can focus on those topics in my future lessons.
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!
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 👍
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).