diff options
author | Christopher Lenz <cmlenz@apache.org> | 2008-05-20 20:15:05 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@apache.org> | 2008-05-20 20:15:05 +0000 |
commit | 3a08b41f8c2a97eee0904b6359e559ed76dfc9fd (patch) | |
tree | 7d5f372c008ede02b896e3bf757afd3c8430967b /share/www/script/couch.js | |
parent | 9cd5e9810997f7255287cb283e9829f1f3512fac (diff) |
Some javascript code cleanup.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@658409 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/couch.js')
-rw-r--r-- | share/www/script/couch.js | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js index d63f1eae..0b2f828c 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -94,12 +94,19 @@ function CouchDB(name) { } // Applies the map function to the contents of database and returns the results. - this.query = function(mapFun, options) { + this.query = function(mapFun, reduceFun, options) { + var body = {language: "javascript"}; if (typeof(mapFun) != "string") mapFun = mapFun.toSource ? mapFun.toSource() : "(" + mapFun.toString() + ")"; + body.map = mapFun; + if (reduceFun != null) { + if (typeof(reduceFun) != "string") + reduceFun = reduceFun.toSource ? reduceFun.toSource() : "(" + reduceFun.toString() + ")"; + body.reduce = reduceFun; + } var req = request("POST", this.uri + "_temp_view" + encodeOptions(options), { headers: {"Content-Type": "application/json"}, - body: JSON.stringify({language:"javascript",map:mapFun}) + body: JSON.stringify(body) }); var result = JSON.parse(req.responseText); if (req.status != 200) @@ -107,22 +114,6 @@ function CouchDB(name) { return result; } - // Applies the map function to the contents of database and returns the results. - this.reduce_query = function(mapFun, reduceFun, options) { - if (typeof(mapFun) != "string") - mapFun = mapFun.toSource ? mapFun.toSource() : "(" + mapFun.toString() + ")"; - if (typeof(reduceFun) != "string") - reduceFun = reduceFun.toSource ? reduceFun.toSource() : "(" + reduceFun.toString() + ")"; - var req = request("POST", this.uri + "_temp_view" + encodeOptions(options), { - headers: {"Content-Type": "application/json"}, - body: JSON.stringify({language:"javascript",map:mapFun,reduce:reduceFun}) - }); - var result = JSON.parse(req.responseText); - if (req.status != 200) - throw result; - return result; - } - this.view = function(viewname, options) { var req = request("GET", this.uri + "_view/" + viewname + encodeOptions(options)); if (req.status == 404) |