On 2011-06-09, at 15:47 , Daniel Itaboraí wrote:

> This is great stuff!
> 
> It would be nice to have some more operations like "increment", "decrement",
> "push", "pop", "compare-and-swap", etc. I think error handling should be
> better addressed, possibly returning an array of "result" objects (or
> something similar).
> 
> Also, I don´t think one should mention idempotency of patches, since they
> seem to me inherently state dependent.
> 
> regards,
> Daniel

This sort of update seems to be better implemented with update handlers. Even 
simple cases like decrement can create lots of cases. What to do at 0? Do we 
support decrement other than one? Do we support decrement of non-integral 
values? How about the case where the value isn't a number or doesn't exist? All 
of these cases are easily taken care of by update handlers. We can even write 
an update handler that calls other update handlers thanks to code-sharing via 
common-js modules. Now there is debate as to how easy it is to write some of 
those and if CouchDB should make some of it easier but it's a start on the 
single document level. (Also, bulk update calls would be interesting but that's 
another thread.)

Now what I see PATCH being useful for is efficiency. It not only allows you to 
avoid large repetition in payload but could also have slightly better 
concurrency since one could check the current revision against the request's 
revision for just the given patches. One could approximate this with an update 
handler though this might have elegance since it could work out of the box if 
the specification of JSON PATCH is carefully crafted and implemented. For now 
it's just interesting though since I think we'll get more milage from update 
handler improvements. Maybe the future will include PATCH support, maybe not.

Brian.

Reply via email to