incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: validate_doc_update modifying doc?
Date Fri, 01 May 2009 00:32:41 GMT
On Thu, Apr 30, 2009 at 3:42 AM, Brian Candler <B.Candler@pobox.com> wrote:
> On Wed, Apr 29, 2009 at 04:47:41PM +0200, Wout Mertens wrote:
>> On Apr 29, 2009, at 11:14 AM, Chris Anderson wrote:
>>
>>> However, I think we should add an _update handler which allows
>>> JavaScript
>>> to transform arbitrary input into JSON before saving. This should open
>>> up
>>> the range of possibility a bit without JS needing the ability to make
>>> HTTP calls.
>>
>> Hmmm... Could that then be used to update only one field of a doc? How
>> would this work with revisions?
>
> It could, if the input to the function included the original doc.

Yes I think that'd be nice. Maybe update can have both a PUT and a
POST mode (so the oldDoc could be made available in PUT when there was
an old version.

> Perhaps
> something like:
>
>  function(post_body, oldDoc, userCtx, http_headers) {
>    ...
>  }
>

This function signature isn't _quite_ what I'd implement, but it's
close. If anyone decides to write this code I'd be glad to help. It
should be just a matter of snapping together various pieces that are
already used by _show and externals.

> In that case, it could emit a new document which is oldDoc merged with
> post_body.
>
> It could be useful if post_body were first decoded into an object following
> the way that Rack/Rails handle form posts:
>
>  foo=1&bar=2                 =>   {"foo":"1","bar":"2"}
>  foo[]=1&foo[]=2             =>   {"foo":["1","2"]}
>  foo[bar]=1&foo[baz]=2       =>   {"foo":{"bar":"1","baz":"2"}}
>
> Regards,
>
> Brian.
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Mime
View raw message