couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1036813 - in /couchdb/trunk: share/www/script/test/design_docs.js share/www/script/test/view_pagination.js src/couchdb/couch_httpd_view.erl
Date Fri, 19 Nov 2010 12:19:38 GMT
Author: fdmanana
Date: Fri Nov 19 12:19:38 2010
New Revision: 1036813

URL: http://svn.apache.org/viewvc?rev=1036813&view=rev
Log:
Add aliases start_key, end_key, start_key_docid and end_key_docid.
Closes COUCHDB-949.


Modified:
    couchdb/trunk/share/www/script/test/design_docs.js
    couchdb/trunk/share/www/script/test/view_pagination.js
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/test/design_docs.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/design_docs.js?rev=1036813&r1=1036812&r2=1036813&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/design_docs.js (original)
+++ couchdb/trunk/share/www/script/test/design_docs.js Fri Nov 19 12:19:38 2010
@@ -286,6 +286,10 @@ couchTests.design_docs = function(debug)
     result = db.view("test/summate", {startkey: 4, endkey: 6});
     T(result.rows[0].value == 15);
 
+    // test start_key and end_key aliases
+    result = db.view("test/summate", {start_key: 4, end_key: 6});
+    T(result.rows[0].value == 15);
+
     // Verify that a shared index (view def is an exact copy of "summate")
     // does not confuse the reduce stage
     result = db.view("test/summate2", {startkey: 4, endkey: 6});

Modified: couchdb/trunk/share/www/script/test/view_pagination.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/view_pagination.js?rev=1036813&r1=1036812&r2=1036813&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/view_pagination.js (original)
+++ couchdb/trunk/share/www/script/test/view_pagination.js Fri Nov 19 12:19:38 2010
@@ -36,6 +36,19 @@ couchTests.view_pagination = function(de
       for (j = 0; j < 10;j++) {
         T(queryResults.rows[j].key == i + j);
       }
+
+      // test aliases start_key and start_key_docid
+      queryResults = db.query(queryFun, null, {
+        start_key: i,
+        start_key_docid: i,
+        limit: 10
+      });
+      T(queryResults.rows.length == 10);
+      T(queryResults.total_rows == docs.length);
+      T(queryResults.offset == i);
+      for (j = 0; j < 10;j++) {
+        T(queryResults.rows[j].key == i + j);
+      }
     }
 
     // page through the view descending
@@ -72,51 +85,63 @@ couchTests.view_pagination = function(de
       }
     }
 
+    function testEndkeyDocId(queryResults) {
+      T(queryResults.rows.length == 35);
+      T(queryResults.total_rows == docs.length);
+      T(queryResults.offset == 1);
+      T(queryResults.rows[0].id == "1");
+      T(queryResults.rows[1].id == "10");
+      T(queryResults.rows[2].id == "11");
+      T(queryResults.rows[3].id == "12");
+      T(queryResults.rows[4].id == "13");
+      T(queryResults.rows[5].id == "14");
+      T(queryResults.rows[6].id == "15");
+      T(queryResults.rows[7].id == "16");
+      T(queryResults.rows[8].id == "17");
+      T(queryResults.rows[9].id == "18");
+      T(queryResults.rows[10].id == "19");
+      T(queryResults.rows[11].id == "2");
+      T(queryResults.rows[12].id == "20");
+      T(queryResults.rows[13].id == "21");
+      T(queryResults.rows[14].id == "22");
+      T(queryResults.rows[15].id == "23");
+      T(queryResults.rows[16].id == "24");
+      T(queryResults.rows[17].id == "25");
+      T(queryResults.rows[18].id == "26");
+      T(queryResults.rows[19].id == "27");
+      T(queryResults.rows[20].id == "28");
+      T(queryResults.rows[21].id == "29");
+      T(queryResults.rows[22].id == "3");
+      T(queryResults.rows[23].id == "30");
+      T(queryResults.rows[24].id == "31");
+      T(queryResults.rows[25].id == "32");
+      T(queryResults.rows[26].id == "33");
+      T(queryResults.rows[27].id == "34");
+      T(queryResults.rows[28].id == "35");
+      T(queryResults.rows[29].id == "36");
+      T(queryResults.rows[30].id == "37");
+      T(queryResults.rows[31].id == "38");
+      T(queryResults.rows[32].id == "39");
+      T(queryResults.rows[33].id == "4");
+      T(queryResults.rows[34].id == "40");
+    }
+
     // test endkey_docid
-    var queryResults = db.query(function(doc) { emit(null, null);}, null, {
+    var queryResults = db.query(function(doc) { emit(null, null); }, null, {
       startkey: null,
       startkey_docid: 1,
       endkey: null,
       endkey_docid: 40
     });
+    testEndkeyDocId(queryResults);
 
-    T(queryResults.rows.length == 35);
-    T(queryResults.total_rows == docs.length);
-    T(queryResults.offset == 1);
-    T(queryResults.rows[0].id == "1");
-    T(queryResults.rows[1].id == "10");
-    T(queryResults.rows[2].id == "11");
-    T(queryResults.rows[3].id == "12");
-    T(queryResults.rows[4].id == "13");
-    T(queryResults.rows[5].id == "14");
-    T(queryResults.rows[6].id == "15");
-    T(queryResults.rows[7].id == "16");
-    T(queryResults.rows[8].id == "17");
-    T(queryResults.rows[9].id == "18");
-    T(queryResults.rows[10].id == "19");
-    T(queryResults.rows[11].id == "2");
-    T(queryResults.rows[12].id == "20");
-    T(queryResults.rows[13].id == "21");
-    T(queryResults.rows[14].id == "22");
-    T(queryResults.rows[15].id == "23");
-    T(queryResults.rows[16].id == "24");
-    T(queryResults.rows[17].id == "25");
-    T(queryResults.rows[18].id == "26");
-    T(queryResults.rows[19].id == "27");
-    T(queryResults.rows[20].id == "28");
-    T(queryResults.rows[21].id == "29");
-    T(queryResults.rows[22].id == "3");
-    T(queryResults.rows[23].id == "30");
-    T(queryResults.rows[24].id == "31");
-    T(queryResults.rows[25].id == "32");
-    T(queryResults.rows[26].id == "33");
-    T(queryResults.rows[27].id == "34");
-    T(queryResults.rows[28].id == "35");
-    T(queryResults.rows[29].id == "36");
-    T(queryResults.rows[30].id == "37");
-    T(queryResults.rows[31].id == "38");
-    T(queryResults.rows[32].id == "39");
-    T(queryResults.rows[33].id == "4");
-    T(queryResults.rows[34].id == "40");
+    // test aliases end_key_docid and end_key
+    queryResults = db.query(function(doc) { emit(null, null); }, null, {
+      start_key: null,
+      start_key_docid: 1,
+      end_key: null,
+      end_key_docid: 40
+    });
+    testEndkeyDocId(queryResults);
 
   };

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=1036813&r1=1036812&r2=1036813&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Fri Nov 19 12:19:38 2010
@@ -269,14 +269,26 @@ parse_view_param("", _) ->
 parse_view_param("key", Value) ->
     JsonKey = ?JSON_DECODE(Value),
     [{start_key, JsonKey}, {end_key, JsonKey}];
+% TODO: maybe deprecate startkey_docid
 parse_view_param("startkey_docid", Value) ->
     [{start_docid, ?l2b(Value)}];
+parse_view_param("start_key_docid", Value) ->
+    [{start_docid, ?l2b(Value)}];
+% TODO: maybe deprecate endkey_docid
 parse_view_param("endkey_docid", Value) ->
     [{end_docid, ?l2b(Value)}];
+parse_view_param("end_key_docid", Value) ->
+    [{end_docid, ?l2b(Value)}];
+% TODO: maybe deprecate startkey
 parse_view_param("startkey", Value) ->
     [{start_key, ?JSON_DECODE(Value)}];
+parse_view_param("start_key", Value) ->
+    [{start_key, ?JSON_DECODE(Value)}];
+% TODO: maybe deprecate endkey
 parse_view_param("endkey", Value) ->
     [{end_key, ?JSON_DECODE(Value)}];
+parse_view_param("end_key", Value) ->
+    [{end_key, ?JSON_DECODE(Value)}];
 parse_view_param("limit", Value) ->
     [{limit, parse_positive_int_param(Value)}];
 parse_view_param("count", _Value) ->
@@ -325,10 +337,12 @@ warn_on_empty_key_range(#view_query_args
     case {Dir, couch_view:less_json(StartKey, EndKey)} of
         {fwd, false} ->
             throw({query_parse_error,
-            <<"No rows can match your key range, reverse your startkey and endkey or
set descending=true">>});
+            <<"No rows can match your key range, reverse your ",
+                "start_key and end_key or set descending=true">>});
         {rev, true} ->
             throw({query_parse_error,
-            <<"No rows can match your key range, reverse your startkey and endkey or
set descending=false">>});
+            <<"No rows can match your key range, reverse your ",
+                "start_key and end_key or set descending=false">>});
         _ -> ok
     end.
 



Mime
View raw message