couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r756413 - in /couchdb/trunk: share/www/script/futon.browse.js share/www/script/jquery.couch.js share/www/script/test/view_errors.js src/couchdb/couch_httpd_view.erl
Date Fri, 20 Mar 2009 10:58:53 GMT
Author: jchris
Date: Fri Mar 20 10:58:52 2009
New Revision: 756413

URL: http://svn.apache.org/viewvc?rev=756413&view=rev
Log:
map queries with group=true query option will return an error.
closes COUCHDB-185. 
changes to jquery.couch.js to support ajaxOptions may be useful for more than just openDoc,
will need to be spread to the rest of the API.

Modified:
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/jquery.couch.js
    couchdb/trunk/share/www/script/test/view_errors.js
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=756413&r1=756412&r2=756413&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Fri Mar 20 10:58:52 2009
@@ -301,7 +301,7 @@
               page.storedViewLanguage = page.viewLanguage;
               if (callback) callback();
             }
-          });
+          },{async:false});
         } else {
           page.updateViewEditor(page.storedViewCode.map,
             page.storedViewCode.reduce || "");
@@ -467,9 +467,6 @@
         if (options.limit === undefined) {
           options.limit = parseInt($("#perpage").val(), 10);
         }
-        if (options.group === undefined) {
-          options.group = true;
-        }
         if ($("#documents thead th.key").is(".desc")) {
           if (typeof options.descending == 'undefined') options.descending = true;
           var descend = true;
@@ -589,6 +586,7 @@
             var reduceFun = $("#viewcode_reduce").val() || null;
             if (reduceFun != null) {
               $.cookies.set(db.name + ".reduce", reduceFun);
+              options.group = true;
             } else {
               $.cookies.remove(db.name + ".reduce");
             }
@@ -602,6 +600,9 @@
             $("#viewcode").show();
             var currentMapCode = $("#viewcode_map").val();
             var currentReduceCode = $("#viewcode_reduce").val() || null;
+            if (currentReduceCode) {
+              options.group = true;
+            }
             if (page.isDirty) {
               db.query(currentMapCode, currentReduceCode, page.viewLanguage, options);
             } else {

Modified: couchdb/trunk/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.couch.js?rev=756413&r1=756412&r2=756413&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.couch.js [utf-8] Fri Mar 20 10:58:52 2009
@@ -205,9 +205,10 @@
             alert("please provide an eachApp function for allApps()");
           }
         },
-        openDoc: function(docId, options) {
+        openDoc: function(docId, options, ajaxOptions) {
           options = options || {};
-          $.ajax({
+          ajaxOptions = ajaxOptions || {};
+          $.ajax($.extend({
             type: "GET",
             url: this.uri + encodeURIComponent(docId) + encodeOptions(options),
             dataType: "json",
@@ -221,7 +222,7 @@
                 alert("The document could not be retrieved: " + resp.reason);
               }
             }
-          });
+          }, ajaxOptions));
         },
         saveDoc: function(doc, options) {
           options = options || {};

Modified: couchdb/trunk/share/www/script/test/view_errors.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/view_errors.js?rev=756413&r1=756412&r2=756413&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/view_errors.js (original)
+++ couchdb/trunk/share/www/script/test/view_errors.js Fri Mar 20 10:58:52 2009
@@ -49,4 +49,41 @@
     })
   });
   T(JSON.parse(xhr.responseText).error == "invalid_json");
+  
+  var map = function (doc) {emit(doc.integer, doc.integer);};
+  
+  try {
+      db.query(map, null, {group: true});
+      T(0 == 1);
+  } catch(e) {
+      T(e.error == "query_parse_error");
+  }
+  
+  // reduce=false on map views doesn't work, so group=true will
+  // never throw for temp reduce views.
+  
+  var designDoc = {
+    _id:"_design/test",
+    language: "javascript",
+    views: {
+      no_reduce: {map:"function(doc) {emit(doc._id, null);}"},
+      with_reduce: {map:"function (doc) {emit(doc.integer, doc.integer)};",
+                reduce:"function (keys, values) { return sum(values); };"},
+    }
+  };
+  T(db.save(designDoc).ok);
+  
+  try {
+      db.view("test/no_reduce", {group: true});
+      T(0 == 1);
+  } catch(e) {
+      T(e.error == "query_parse_error");
+  }
+  
+  try {
+      db.view("test/with_reduce", {group: true, reduce: false});
+      T(0 == 1);
+  } catch(e) {
+      T(e.error == "query_parse_error");
+  }
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=756413&r1=756412&r2=756413&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Fri Mar 20 10:58:52 2009
@@ -97,6 +97,7 @@
         start_key = StartKey,
         start_docid = StartDocId
     } = QueryArgs,
+    validate_map_query(QueryArgs),
     CurrentEtag = view_group_etag(Group),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() -> 
         {ok, RowCount} = couch_view:get_row_count(View),
@@ -114,6 +115,7 @@
         skip = SkipCount,
         start_docid = StartDocId
     } = QueryArgs,
+    validate_map_query(QueryArgs),
     CurrentEtag = view_group_etag(Group, Keys),
     couch_httpd:etag_respond(Req, CurrentEtag, fun() ->     
         {ok, RowCount} = couch_view:get_row_count(View),
@@ -134,6 +136,13 @@
         finish_view_fold(Req, RowCount, FoldResult)
     end).
 
+validate_map_query(QueryArgs) ->
+    case QueryArgs#view_query_args.group_level of
+    0 -> ok;
+    _ ->
+        throw({query_parse_error, <<"Query parameter \"group\" and/or \"group_level\"
are invalid for map views.">>})
+    end.
+
 output_reduce_view(Req, View, Group, QueryArgs, nil) ->
     #view_query_args{
         start_key = StartKey,



Mime
View raw message