Skip to content

Instantly share code, notes, and snippets.

@gbrennon
Created December 23, 2015 18:12
Show Gist options
  • Save gbrennon/195ab7f9e52d9c46df39 to your computer and use it in GitHub Desktop.
Save gbrennon/195ab7f9e52d9c46df39 to your computer and use it in GitHub Desktop.
angular.module('suapraia.services', [])
.factory('BalnFact', BalnFact);
function BalnFact($q) {
var _db;
var _beaches;
var _expire_date;
return {
initDB: initDB,
addBeach: addBeach,
getBeaches: getBeaches
}
function initDB() {
_db = new PouchDB('beaches', {adapter: 'websql'});
}
function addBeach(beach) {
return $q.when(_db.put(beach));
}
function getBeaches() {
if(!_beaches) {
return $q.when(_db.allDocs({include_docs: true}))
.then(function(docs) {
_beaches = docs.rows.map(function(row) {
return row.doc;
});
return _beaches;
});
} else {
return $q.when(_beaches);
}
}
function delBeach(beach) {
return $q.when(_db.remove(beach));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment