diff options
| author | John Christopher Anderson <jchris@apache.org> | 2009-03-13 22:15:34 +0000 | 
|---|---|---|
| committer | John Christopher Anderson <jchris@apache.org> | 2009-03-13 22:15:34 +0000 | 
| commit | 9007e2d21dea8b0185c0096b30364a8ee40a3867 (patch) | |
| tree | 7d8dacb2c8cd619f18dfab8fdb40d146ac28c85a /share/www/script/couch.js | |
| parent | 65608e14e8911b33c30178d717d745edc9f66c17 (diff) | |
Commit Damien's rep_security branch to trunk. 
Changes bulk_docs conflict checking. 
Breaks file format, see mailing list for data upgrade procedure, or
http://wiki.apache.org/couchdb/Breaking_changes
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@753448 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/couch.js')
| -rw-r--r-- | share/www/script/couch.js | 44 | 
1 files changed, 36 insertions, 8 deletions
| diff --git a/share/www/script/couch.js b/share/www/script/couch.js index 821fb694..4586cca8 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -98,15 +98,26 @@ function CouchDB(name, httpHeaders) {        if (docs[i]._id == undefined)          docs[i]._id = newUuids.pop();      } -    this.last_req = this.request("POST", this.uri + "_bulk_docs" + encodeOptions(options), { -      body: JSON.stringify({"docs": docs}) +    var json = {"docs": docs}; +    // put any options in the json +    for (var option in options) { +      json[option] = options[option]; +    } +    this.last_req = this.request("POST", this.uri + "_bulk_docs", { +      body: JSON.stringify(json)      }); -    CouchDB.maybeThrowError(this.last_req); -    var result = JSON.parse(this.last_req.responseText); -    for (var i = 0; i < docs.length; i++) { -        docs[i]._rev = result.new_revs[i].rev; +    if (this.last_req.status == 417) { +      return {errors: JSON.parse(this.last_req.responseText)}; +    } +    else { +      CouchDB.maybeThrowError(this.last_req); +      var results = JSON.parse(this.last_req.responseText); +      for (var i = 0; i < docs.length; i++) { +        if(results[i].rev) +          docs[i]._rev = results[i].rev; +      } +      return results;      } -    return result;    }    this.ensureFullCommit = function() { @@ -203,6 +214,20 @@ function CouchDB(name, httpHeaders) {      return JSON.parse(this.last_req.responseText);    } +  this.setDbProperty = function(propId, propValue) { +    this.last_req = this.request("PUT", this.uri + propId,{ +      body:JSON.stringify(propValue) +    }); +    CouchDB.maybeThrowError(this.last_req); +    return JSON.parse(this.last_req.responseText); +  } +   +  this.getDbProperty = function(propId) { +    this.last_req = this.request("GET", this.uri + propId); +    CouchDB.maybeThrowError(this.last_req); +    return JSON.parse(this.last_req.responseText); +  } +      this.setAdmins = function(adminsArray) {      this.last_req = this.request("PUT", this.uri + "_admins",{        body:JSON.stringify(adminsArray) @@ -283,8 +308,11 @@ CouchDB.getVersion = function() {    return JSON.parse(CouchDB.last_req.responseText).version;  } -CouchDB.replicate = function(source, target) { +CouchDB.replicate = function(source, target, rep_options) { +  rep_options = rep_options || {}; +  var headers = rep_options.headers || {};    CouchDB.last_req = CouchDB.request("POST", "/_replicate", { +    headers: headers,      body: JSON.stringify({source: source, target: target})    });    CouchDB.maybeThrowError(CouchDB.last_req); | 
