couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject svn commit: r957466 - in /couchdb/branches/0.11.x: share/www/script/test/rewrite.js src/couchdb/couch_httpd_rewrite.erl
Date Thu, 24 Jun 2010 09:18:16 GMT
Author: benoitc
Date: Thu Jun 24 09:18:16 2010
New Revision: 957466

URL: http://svn.apache.org/viewvc?rev=957466&view=rev
Log:
allows more complex keys in the rewriter, so it could ease the
pagination (only array for now) :

{
  "from": "simpleForm/complexView5/:a/:b",
  "to": "_list/simpleForm/complexView3",
  "query": {
    "key": [":a", ":b"]
  }
},

Modified:
    couchdb/branches/0.11.x/share/www/script/test/rewrite.js
    couchdb/branches/0.11.x/src/couchdb/couch_httpd_rewrite.erl

Modified: couchdb/branches/0.11.x/share/www/script/test/rewrite.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/rewrite.js?rev=957466&r1=957465&r2=957466&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/rewrite.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/rewrite.js Thu Jun 24 09:18:16 2010
@@ -212,6 +212,13 @@ couchTests.rewrite = function(debug) {
                   emit(doc.a, doc.string);
                 }
               })
+            },
+            complexView3: {
+              map: stringFun(function(doc) {
+                if (doc.type == "complex") {
+                  emit(doc.b, doc.string);
+                }
+              })
             }
           }
         }
@@ -320,6 +327,9 @@ couchTests.rewrite = function(debug) {
         T(xhr.status == 200, "with query params");
         T(/Value: doc 5/.test(xhr.responseText));
         
+        xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/simpleForm/complexView5/test/essai");
+        T(xhr.status == 200, "with query params");
+        T(/Value: doc 4/.test(xhr.responseText));
         
         // test path relative to server
         designDoc.rewrites.push({

Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd_rewrite.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_rewrite.erl?rev=957466&r1=957465&r2=957466&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd_rewrite.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_rewrite.erl Thu Jun 24 09:18:16 2010
@@ -242,8 +242,18 @@ make_query_list([{Key, Value}|Rest], Bin
 replace_var(Key, Value, Bindings) ->
     case Value of
         <<":", Var/binary>> ->
-            Var1 = list_to_atom(binary_to_list(Var)),
-            proplists:get_value(Var1, Bindings, Value);
+            get_var(Var, Bindings, Value);
+        _ when is_list(Value) ->
+            Value1 = lists:foldr(fun(V, Acc) ->
+                V1 = case V of
+                    <<":", VName/binary>> ->
+                        get_var(VName, Bindings, V);
+                    _ ->
+                        V
+                end,
+                [V1|Acc]
+            end, [], Value),
+            to_json(Value1);
         _ when is_binary(Value) ->
             Value;
         _ ->
@@ -257,6 +267,10 @@ replace_var(Key, Value, Bindings) ->
     end.
 
 
+get_var(VarName, Props, Default) ->
+    VarName1 = list_to_atom(binary_to_list(VarName)),
+    proplists:get_value(VarName1, Props, Default).
+
 %% doc: build new patch from bindings. bindings are query args
 %% (+ dynamic query rewritten if needed) and bindings found in
 %% bind_path step.



Mime
View raw message