Mykyta Machekhin
03/28/2022, 6:01 PM.create, .update etc) are not work at all if I don’t use await, .then or .catch on this methods. Can someone explain me why is it?Austin Zentz
03/28/2022, 8:59 PMAustin Zentz
03/28/2022, 9:00 PMAustin Zentz
03/28/2022, 9:00 PMsuperbunches
03/28/2022, 9:28 PMawait -ing from Prisma is confirmation that something happened during your CRUD operation. Which can be success or failure.
For example, if you wanted to say “Prisma, add a Widget to the database with an id of `123`”, how would you feel if it added the Widget but then didn’t tell you anything?
This way, when you ask Prisma to do something, it tells you what happened by saying “Here is proof from the database that I did what you said”. In other words, when you declare:
const body = await prisma.widget.create({
data: {
id: 123
}
});
in most frameworks, this happens within a function where you return a status and a body. The body that is returned is proof that Prisma did its job, and the Widget you asked to be created exists in the database.superbunches
03/28/2022, 9:28 PMbody may also be an error message if something went wrong.Nurul
03/29/2022, 1:32 PMawait them.
This description of when to use await was helpful for me, should be helpful to you as wellMykyta Machekhin
03/29/2022, 11:26 PM