Skip to content

Instantly share code, notes, and snippets.

@mmirolim
Created June 30, 2014 21:25
Show Gist options
  • Save mmirolim/27c2891ddd06ce51dae3 to your computer and use it in GitHub Desktop.
Save mmirolim/27c2891ddd06ce51dae3 to your computer and use it in GitHub Desktop.
Example of pouchDB service in angularjs
app.factory('CacheDB', ['$http', 'API',
function ($http, API) {
var db = new PouchDB('cachedb');
return {
put: function (obj, id) {
db.put(obj, id)
.then(function (r) {
return r;
});
},
get: function (id) {
db.get(id)
.then(function (r) {
console.log(r, 'Result from get');
return r;
});
},
query: function (map) {
db.query({map: map}, {include_docs: true})
.then(function (r) {
return r;
})
},
allDocs: function (startKey, endKey, desc) {
db.allDocs({startkey: startKey, endkey: endKey, descending: desc})
.then(function (r) {
console.log(r, 'Results from allDocs');
return r;
})
}
}
}
]);
@mohammadhafiz
Copy link

hai, can you give me your controller for get id and allDocs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment