couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject svn commit: r928374 - in /couchdb/trunk: share/www/script/test/rewrite.js src/couchdb/couch_httpd_rewrite.erl
Date Sun, 28 Mar 2010 11:17:32 GMT
Author: benoitc
Date: Sun Mar 28 11:17:32 2010
New Revision: 928374

URL: http://svn.apache.org/viewvc?rev=928374&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/trunk/share/www/script/test/rewrite.js
    couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl

Modified: couchdb/trunk/share/www/script/test/rewrite.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/rewrite.js?rev=928374&r1=928373&r2=928374&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/rewrite.js (original)
+++ couchdb/trunk/share/www/script/test/rewrite.js Sun Mar 28 11:17:32 2010
@@ -132,6 +132,14 @@ couchTests.rewrite = function(debug) {
               }
             },
             {
+              "from": "simpleForm/complexView5/:a/:b",
+              "to": "_list/simpleForm/complexView3",
+              "query": {
+                "key": [":a", ":b"]
+              }
+            },
+            
+            {
               "from": "uuids",
               "to": "../../../_uuids"
             }
@@ -211,6 +219,13 @@ couchTests.rewrite = function(debug) {
                   emit(doc.a, doc.string);
                 }
               })
+            },
+            complexView3: {
+              map: stringFun(function(doc) {
+                if (doc.type == "complex") {
+                  emit(doc.b, doc.string);
+                }
+              })
             }
           }
         }
@@ -319,6 +334,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
         

Modified: couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl?rev=928374&r1=928373&r2=928374&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl Sun Mar 28 11:17:32 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