Skip to content

Instantly share code, notes, and snippets.

@isc-rsingh
Last active August 29, 2015 14:17
Show Gist options
  • Save isc-rsingh/7176d3ee0e1a25b1ab06 to your computer and use it in GitHub Desktop.
Save isc-rsingh/7176d3ee0e1a25b1ab06 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PouchDB write test</title>
</head>
<body>
<div class="container-fluid">
<h1>PouchDB write test</h1>
</div>
</div>
<script src="//cdn.jsdelivr.net/pouchdb/3.3.1/pouchdb.min.js"></script>
<script>
var db = new PouchDB('tiny', {'auto_compaction':true});
console.log('After new pouchdb');
var c4 = -4;
db.info().then(function (res) {
c4 = res.doc_count;
console.log('DB info after new pouchdb: '+c4);
});
db.destroy()
.then(function (response) {
console.log('Done destroying, starting load');
db = loadDoc(new PouchDB('tiny', {'auto_compaction':true}));
var c6 = -6;
db.info().then(function (res) {
c6 = res.doc_count;
console.log('DB info in destroy: '+c6);
}).catch(function (err) {
console.log('Error in info in destroy: '+err);
});
});
var c5 = -2;
db.info().then(function (res) {
c5 = res.doc_count;
console.log('DB info at the END: '+c5);
});
function loadDoc(db) {
db.put({_id:'mydoc',title:'Kitties'})
.then(function (response) {
console.log('Success in loadDoc');
return db;
}).catch(function (err) {
console.log('Error in loadDoc: '+err);
return null;
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment