prisma: Prisma Client: add `updateOrThrow()` & `deleteOrThrow()`
I think it makes sense to have rejectOnNotFound
on update
also, and I think it is very weird that it throws an exception instead of returning null
.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 45
- Comments: 24 (1 by maintainers)
+1 for this issue, I think it should return null if record doesnt exist.
example:
Up!
Do you plan to develop this feature? I agree that it would makes sense to have it.
For those interested in it, it is still possible to use this workaround which use try/catch:
Here is the usage example based on the @SC0d3r comment:
Borrowing from @maximeburri but as an extension as an alternative solution:
Usage
Hi @janpio - I am in agreement with this issue,
rejectOnNotFound
should supportupdate
anddelete
operations.Adding a param like this would be a nice addition!
please do not change the default behavior of update because we rely on it for optimistic concurrency control.
if it needed to have some updateOne without throwing error if not found please add some new method.
Hi!
I think also that update should just return null if a record is not found. In my case it would be much more useful since the query is faster when it is ended immediately after record is found and it will not go through all records every time. I think this would be quite important addition. Currently I have a large table in where updating is quite slow due to the fact that I cannot use update in it since it fails on “An operation failed because it depends on one or more records that were required but not found. Record to update not found.” error each time. Instead I am using updateMany and it is quite inefficient.
Issues #5032 is closed as the ugly error was replaced with a more descriptive error: https://github.com/prisma/prisma/issues/5032#issuecomment-786576567 Can you confirm this is still the exception and error you are getting?