From e8bf8effe8f8aeb86028a7e1b75af1ad375b3d90 Mon Sep 17 00:00:00 2001 From: lmorandini Date: Mon, 21 Jan 2013 16:14:27 +1100 Subject: [PATCH 1/3] Added spatial views handling. --- lib/cradle/database/views.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) { From 954e0a7bb5874279d7f6700ba54432314bf9af77 Mon Sep 17 00:00:00 2001 From: lmorandini Date: Mon, 21 Jan 2013 16:19:38 +1100 Subject: [PATCH 2/3] Added handling of revisions by getAttachment (see issue Cradle's #198) --- lib/cradle/database/attachments.js | 36 +++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) 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) { From e5be32ce14e57c33c59f83caecc1b76d150dfa45 Mon Sep 17 00:00:00 2001 From: lmorandini Date: Wed, 23 Jan 2013 09:11:25 +1100 Subject: [PATCH 3/3] Changed version to reflect the fork. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"],