You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this is a feature request for an option to pass to filter(). i am open to there being a completely different solution to this problem tho, so i will spend most of my time explaining the problem to be solved.
in order to throw a NotFound error, this code uses the get method to retrieve the object to be deleted. however, then, in order to actually delete the object, this function re-queries the db using the filter method which delete is then called on.
to avoid an extra query, but still throw if the object is empty, i use filter, then update, and then finally check the count returned by update, in code that looks like this:
checking this count seems a lil icky to me. therefore i propose a throwIfEmpty option on filter which will throw a NotFound error if filter returns no objects. this way, i don't have to check the count. the resulting code would look like this:
as i said, super open to other solutions! this is just the one i thought of. this is a pretty common use case, so conventionalizing an ergonomic way to accomplish this would be great. thanks!
The text was updated successfully, but these errors were encountered:
this is a feature request for an option to pass to
filter()
. i am open to there being a completely different solution to this problem tho, so i will spend most of my time explaining the problem to be solved.the problem
consider the following code:
in order to throw a
NotFound
error, this code uses theget
method to retrieve the object to be deleted. however, then, in order to actually delete the object, this function re-queries the db using thefilter
method whichdelete
is then called on.to avoid an extra query, but still throw if the object is empty, i use
filter
, thenupdate
, and then finally check thecount
returned byupdate
, in code that looks like this:proposed solution
checking this count seems a lil icky to me. therefore i propose a
throwIfEmpty
option onfilter
which will throw aNotFound
error iffilter
returns no objects. this way, i don't have to check the count. the resulting code would look like this:as i said, super open to other solutions! this is just the one i thought of. this is a pretty common use case, so conventionalizing an ergonomic way to accomplish this would be great. thanks!
The text was updated successfully, but these errors were encountered: