Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAttachment doesn't handle revisions #199

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions lib/cradle/database/attachments.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions lib/cradle/database/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down