Created
December 23, 2015 18:12
-
-
Save gbrennon/195ab7f9e52d9c46df39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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