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

Lots of new features, and a few bug fixes. #1

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f09f311
Added initial support for Design Documents and views.
tommyo Nov 6, 2014
6371cc3
Rewrite of db().all and db().design().view to add parameters.
tommyo Nov 10, 2014
6c23659
Moved all() and view() to accept array of keys to fetch as second param.
tommyo Nov 10, 2014
68cb6d8
Simplified how multiple records are queried.
tommyo Nov 18, 2014
a68cc95
Fixed view query url.
tommyo Nov 27, 2014
91a2ac9
Added support for compound keys in view queries.
tommyo Dec 3, 2014
acbe04c
Better url parsing to support ios urls.
tommyo Dec 16, 2014
4c239d1
Merge remote-tracking branch 'origin/develop'
tommyo Dec 16, 2014
39d5c9e
Update angular-couchbase-lite.js
symbiat Dec 16, 2014
015d441
Fixed url structure to work on all devices.
tommyo Dec 16, 2014
a9eab60
Support document delete query
Jan 23, 2015
ad0fd36
Added _purge, _compact queries
Jan 23, 2015
be9eb34
Added how-to to README
Jan 24, 2015
015caa2
README fixed examples
Jan 25, 2015
a6eb508
Merge pull request #2 from Switch168/master
tommyo Feb 23, 2015
01e9213
Design view document delete
May 8, 2015
82b8aa7
README design examples
May 8, 2015
1e11471
Updated sync to to com.couchbase.lite.phonegap v1.1 API
tommyo Jun 24, 2015
162594e
Added note for older versions of PhoneGap plugin.
tommyo Jun 26, 2015
5a72af0
Add Auth token header in a cleaner way.
tommyo Jun 26, 2015
68e9ac8
Merge pull request #3 from Switch168/master
tommyo Jun 26, 2015
b9b6fcc
Added url method to get host url.
tommyo Sep 11, 2015
a354fc7
Return the promise for the new url method.
tommyo Sep 11, 2015
420a0ee
Fixed design doc delete method.
tommyo Jan 22, 2016
82a65c5
Allow later versions of angular
tommyo Apr 24, 2016
c7bcd45
added support for angular-http-auth plugin
tommyo Jun 17, 2016
a8cdcae
Removed costly debug output.
tommyo Dec 19, 2016
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
Next Next commit
Added initial support for Design Documents and views.
tommyo committed Nov 6, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f09f31186fb8a4d31d125cc941abbeae10f4eccf
103 changes: 99 additions & 4 deletions angular-couchbase-lite.js
Original file line number Diff line number Diff line change
@@ -76,10 +76,11 @@
function (parsedUrl) {
var headers = {Authorization: 'Basic ' + parsedUrl.basicAuthToken},
actions = {
'get': {method: 'GET', headers: headers},
'list': {method: 'GET', headers: headers, isArray: true},
'put': {method: 'PUT', headers: headers},
'post': {method: 'POST', headers: headers}
'get': {method: 'GET', headers: headers},
'list': {method: 'GET', headers: headers, isArray: true},
'put': {method: 'PUT', headers: headers},
'post': {method: 'POST', headers: headers},
'filter': {method: 'POST', headers: headers, isArray: true}
};

return $resource(parsedUrl.url + path, paramDefaults, actions);
@@ -215,6 +216,100 @@
return db.get().$promise;
});
},

all: function (filter) {
$log.debug("Asking Couchbase Lite to get all documents in database [" + databaseName + "]");
var resourceString = ':db/_all_docs';
if (filter) {
$log.debug(JSON.stringify(filter));
return openResource(resourceString, {db: databaseName}).then(function (docs) {
return docs.filter(filter).$promise;
});
} else {
return openResource(resourceString, {db: databaseName}).then(function (docs) {
return docs.list().$promise;
});
}
},

// Design Doc
design: function (designId) {
function cleanFunction(func) {
var type = typeof func;
switch (type) {
case "function":
// stringify and scrub
return String(func).replace(/\s+/g, " ");

case "string":
return func;

default:
throw "Invalid function definition";
}
}

function toDesignDoc(content) {

validateDocument(content);
if (typeof content == "string") {
content = JSON.parse(content);
}
if (typeof content.views != "object") {
throw "Design Doc is missing valid view structure";
}
angular.forEach(content.views, function(value, key) {
value.map = cleanFunction(value.map);

if (typeof value.reduce != "undefined") {
value.reduce = cleanFunction(value.reduce);
}

this[key] = value;

}, content.views);

if (typeof content.language == "undefined") {
content.language = "javascript";
}
return content;
}

var designString = ':db/_design/:designId';

return {
save: function (spec) {
spec = toDesignDoc(spec);

$log.debug("Asking Couchbase Lite to save design document with id [" + designId + "] in database [" + databaseName + "]");
$log.debug(JSON.stringify(spec));
return openResource(designString, {db: databaseName, designId: designId}).then(function (document) {
return document.put(spec).$promise;
});
},
load: function () {
$log.debug("Asking Couchbase Lite to load design document with id [" + designId + "] in database [" + databaseName + "]");
return openResource(designString, {db: databaseName, designId: designId}).then(function (document) {
return document.get().$promise;
});
},
view: function (id, filter) {
$log.debug("Asking Couchbase Lite to query view with id [" + designId + "/" + id + "] in database [" + databaseName + "]");
var viewString = designString + '/:id';

if (filter) {
$log.debug(JSON.stringify(filter));
return openResource(viewString, {db: databaseName, designId: designId, id: id}).then(function (docs) {
return docs.filter(filter).$promise;
});
} else {
return openResource(viewString, {db: databaseName, designId: designId, id: id}).then(function (docs) {
return docs.list().$promise;
});
}
}
};
},

// Documents
document: function (id) {