diff --git a/lib/cradle/database/attachments.js b/lib/cradle/database/attachments.js index 988334b..254317a 100644 --- a/lib/cradle/database/attachments.js +++ b/lib/cradle/database/attachments.js @@ -1,17 +1,27 @@ -var querystring = require('querystring'), - Args = require('vargs').Constructor, - cradle = require('../../cradle'), - Database = require('./index').Database; +var querystring = require('querystring'), Args = require('vargs').Constructor, cradle = require('../../cradle'), Database = require('./index').Database; -Database.prototype.getAttachment = function (id, attachmentName, callback) { - // - // TODO: Update cache? - // - - return this.connection.rawRequest({ - method: 'GET', - path: '/' + [this.name, querystring.escape(id), attachmentName].join('/') - }, callback); +Database.prototype.getAttachment = function(id, attachmentName, callback) { + + // + // TODO: Update cache? + // + + // If id is an object, the attachment has a revision (defined as {id: id, rev: rev}), + // hence a specific revision is requested to the database + var path = '/' + + [ + this.name, + (typeof id === "object") ? querystring.escape(id.id) : querystring + .escape(id), attachmentName ].join('/'); + + if (typeof id === "object") { + path = path + "?rev=" + id.rev + } + + return this.connection.rawRequest({ + method: 'GET', + path: path + }, callback); }; Database.prototype.removeAttachment = function (doc, attachmentName, callback) { diff --git a/lib/cradle/database/views.js b/lib/cradle/database/views.js index 3422c6d..66b61d9 100644 --- a/lib/cradle/database/views.js +++ b/lib/cradle/database/views.js @@ -12,6 +12,18 @@ Database.prototype.all = function (options, callback) { return this._getOrPostView('/_all_docs', options, callback); }; +//Queries a spatial view, passing any options to the query string. +//Some query string parameters' values have to be JSON-encoded. +Database.prototype.spatialview = function (path, options) { +var callback = new(Args)(arguments).callback, + body; + +path = path.split('/'); +path = ['_design', path[0], '_spatial', path[1]].map(querystring.escape).join('/'); + +return this._getOrPostView(path, options, callback); +}; + // Query a view, passing any options to the query string. // Some query string parameters' values have to be JSON-encoded. Database.prototype.view = function (path, options, callback) { diff --git a/package.json b/package.json index 10dd482..b66461a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cradle", - "version": "0.6.4", + "version": "0.6.4-AURIN", "description": "the high-level, caching, CouchDB library", "url": "http://cloudhead.io/cradle", "keywords": ["couchdb", "database", "couch"],