fix confusion due to magic 'this' object.
This commit is contained in:
@@ -14,9 +14,9 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {};
|
|||||||
// TODO Add user/password arguments for couchdb authentication support.
|
// TODO Add user/password arguments for couchdb authentication support.
|
||||||
my.CouchDBWrapper = function(db_url, view_url, options) {
|
my.CouchDBWrapper = function(db_url, view_url, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.endpoint = db_url;
|
self.endpoint = db_url;
|
||||||
this.view_url = (view_url) ? view_url : db_url+'/'+'_all_docs';
|
self.view_url = (view_url) ? view_url : db_url+'/'+'_all_docs';
|
||||||
this.options = _.extend({
|
self.options = _.extend({
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
},
|
},
|
||||||
options);
|
options);
|
||||||
@@ -45,9 +45,9 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {};
|
|||||||
// @return promise compatible deferred object.
|
// @return promise compatible deferred object.
|
||||||
this.mapping = function() {
|
this.mapping = function() {
|
||||||
var schemaUrl = self.view_url + '?limit=1&include_docs=true';
|
var schemaUrl = self.view_url + '?limit=1&include_docs=true';
|
||||||
var jqxhr = this._makeRequest({
|
var jqxhr = self._makeRequest({
|
||||||
url: schemaUrl,
|
url: schemaUrl,
|
||||||
dataType: this.options.dataType
|
dataType: self.options.dataType
|
||||||
});
|
});
|
||||||
return jqxhr;
|
return jqxhr;
|
||||||
};
|
};
|
||||||
@@ -58,8 +58,8 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {};
|
|||||||
//
|
//
|
||||||
// @return promise compatible deferred object.
|
// @return promise compatible deferred object.
|
||||||
this.get = function(_id) {
|
this.get = function(_id) {
|
||||||
var base = this.endpoint + '/' + _id;
|
var base = self.endpoint + '/' + _id;
|
||||||
return this._makeRequest({
|
return self._makeRequest({
|
||||||
url: base,
|
url: base,
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
});
|
});
|
||||||
@@ -73,13 +73,13 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {};
|
|||||||
// @return deferred supporting promise API
|
// @return deferred supporting promise API
|
||||||
this.upsert = function(doc) {
|
this.upsert = function(doc) {
|
||||||
var data = JSON.stringify(doc);
|
var data = JSON.stringify(doc);
|
||||||
url = this.endpoint;
|
url = self.endpoint;
|
||||||
if (doc._id) {
|
if (doc._id) {
|
||||||
url += '/' + doc._id;
|
url += '/' + doc._id;
|
||||||
}
|
}
|
||||||
// use a PUT, not a POST to update the document:
|
// use a PUT, not a POST to update the document:
|
||||||
// http://wiki.apache.org/couchdb/HTTP_Document_API#POST
|
// http://wiki.apache.org/couchdb/HTTP_Document_API#POST
|
||||||
return this._makeRequest({
|
return self._makeRequest({
|
||||||
url: url,
|
url: url,
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -95,9 +95,9 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {};
|
|||||||
// @param {Object} id id of object to delete
|
// @param {Object} id id of object to delete
|
||||||
// @return deferred supporting promise API
|
// @return deferred supporting promise API
|
||||||
this.delete = function(_id) {
|
this.delete = function(_id) {
|
||||||
url = this.endpoint;
|
url = self.endpoint;
|
||||||
url += '/' + _id;
|
url += '/' + _id;
|
||||||
return this._makeRequest({
|
return self._makeRequest({
|
||||||
url: url,
|
url: url,
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
@@ -131,14 +131,14 @@ this.recline.Backend.CouchDB = this.recline.Backend.CouchDB || {};
|
|||||||
// @param {Object} additional couchdb view query options.
|
// @param {Object} additional couchdb view query options.
|
||||||
// @return deferred supporting promise API
|
// @return deferred supporting promise API
|
||||||
this.query = function(query_object, query_options) {
|
this.query = function(query_object, query_options) {
|
||||||
var norm_q = this._normalizeQuery(query_object);
|
var norm_q = self._normalizeQuery(query_object);
|
||||||
var url = this.view_url;
|
var url = self.view_url;
|
||||||
var q = _.extend(query_options, norm_q);
|
var q = _.extend(query_options, norm_q);
|
||||||
|
|
||||||
var jqxhr = this._makeRequest({
|
var jqxhr = self._makeRequest({
|
||||||
url: url,
|
url: url,
|
||||||
data: JSON.stringify(q),
|
data: JSON.stringify(q),
|
||||||
dataType: this.options.dataType,
|
dataType: self.options.dataType,
|
||||||
});
|
});
|
||||||
return jqxhr;
|
return jqxhr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user