On Fri, Apr 30, 2010 at 8:10 PM, J Chris Anderson <[email protected]> wrote: > > On Apr 30, 2010, at 9:53 AM, Zachary Zolton wrote: > >> Hi, >> >> I'd like to get some feedback on enhancing the _rewrite handler. >> >> CouchDB would benefit from being able to handler this kind of rewrite: >> >> { >> "from": "/tags/:tagname", >> "to": "_view/by-tag", >> "query": { "key": ":tagname" } >> } >> >> Of course, you can do this with CouchDB 0.11, however you have to JSON >> string encode the :tagname value in the URL, e.g.: >> >> /tags/%22birthdays%22 >> >> When what I'd really like is: >> >> /tags/birthdays >> > > I ran into this too and was able to work around like this: > > { > "from": "/tags/:tagname", > "to": "_view/by-tag", > "query": { "key": [":tagname"] } > } > > note, the array. this means I had to modify my view... but it worked. > > edge cases... > > it would be nice to have a workaround, but I'm not sure what that should be. > > >> So I modified couch_httpd_rewrite.erl to JSON encode >> key/startkey/endkey parameters, but I've hit a snag. Imagine you also >> want to do the following: >> >> { >> "from": "/year/:year", >> "to": "_view/by-year", >> "query": { "key": ":year" } >> } >> >> This falls on its face (assuming that the by-year view emits numeric >> keys) since the :year value would get JSON encoded to %222010%22 when >> what you want is 2010. So, I suggest we come up a way to indicate when >> a _rewrite query parameter should be treated as a JSON encoded string. >> >> Here are two potential designs I could come up with: >> >> { >> "from": "/tags/:tagname", >> "to": "_view/by-tag", >> "query": { >> "key": { "name": ":tagname", "json_encode": true } >> } >> } >> >> Or: >> >> { >> "from": "/tags/:tagname", >> "to": "_view/by-tag", >> "query": { >> "key": "\":tagname\"" >> } >> } >> >> A benefit to both these approaches would be that they maintain >> backwards compatibility with the current behavior. Any better ideas? >> >> >> Cheers, >> >> Zach > >
mmm key: ":tagname" should work . At least test pass : http://github.com/benoitc/couchdb/blob/master/share/www/script/test/rewrite.js#L102 - benoit
