Perform basic database queries (CRUD) with Prisma Client

Xiaoru Li
InstructorXiaoru Li
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Apart from creating entries, it's also very intuitive to read, update, or delete data from the database with Prisma Client.

In this lesson, we will explore the Prisma Client API for findMany, findOne, updateMany, deleteMany and so on.

Notice that since all these methods are tailored to the schema that we defined earlier, VS Code is aware of what is valid and is able to prompt us with helpful autocomplete options, making it much easier to explore the Prisma Client API.

Xiaoru Li: [0:01] Apart from creating entries, it's also very intuitive to read, update, or delete data from the database with Prisma Client. Let's first populate the database with some more dummy entries to work with.

[0:21] We can use findMany to return all the profile entries. We can also add constraints to filter or search for the entries we care about. For example, only the profiles where the name contains a capital letter A.

[0:45] We can also use findOne to search for a unique entry. Because right now the only unique field in the profile data model is id, only this option is available.

[1:05] Similarly, we can perform single entry updates with new data or perform a batch update with updateMany. This method will return the number of entries affected. We'll use the findMany method again to get all the entries printed out.

[1:41] We can also delete entries with deleteMany and some constraints. Finally, let's clean up the database, so later on we won't have issues with the migration.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today