diff --git a/lib/cradle/database/index.js b/lib/cradle/database/index.js index d40b26f..68c8f4b 100644 --- a/lib/cradle/database/index.js +++ b/lib/cradle/database/index.js @@ -10,6 +10,10 @@ var Database = exports.Database = function (name, connection, opts) { this.opts.cache = false; this.opts.cacheSize = 0; } + + // Workaround https://issues.apache.org/jira/browse/COUCHDB-1415 by default + this.workaroundBug1415 = true; + this.cache = new (cradle.Cache)(this.opts); this.cacheFeed = null; if (this.opts.cache === 'follow') { @@ -47,6 +51,11 @@ Database.prototype.configureCacheFeed = function () { // A wrapper around `Connection.request`, // which prepends the database name. Database.prototype.query = function (options, callback) { + + // XXX: Workaround https://issues.apache.org/jira/browse/COUCHDB-1415 + if (options.body && options.method === 'POST' && this.workaroundBug1415) + options.body.$ts = Date.now(); + options.path = [this.name, options.path].filter(Boolean).join('/'); return this.connection.request(options, callback); }; @@ -88,12 +97,12 @@ Database.prototype.create = function (callback) { Database.prototype.destroy = function (callback) { if (arguments.length > 1) { throw new(Error)("destroy() doesn't take any additional arguments"); - } - + } + this.query({ - method: 'DELETE', - path: '/', - }, callback); + method: 'DELETE', + path: '/', + }, callback); }; //