Skip to content

Instantly share code, notes, and snippets.

@subkitsupport
Last active December 17, 2015 07:29
Show Gist options
  • Save subkitsupport/9b0b606381423ec0670a to your computer and use it in GitHub Desktop.
Save subkitsupport/9b0b606381423ec0670a to your computer and use it in GitHub Desktop.
How to PouchDB Access using Store API Template
<!DOCTYPE html>
<html lang="en">
<head><title>Access to Store-API using PouchDB</title></head>
<body>
<h1>Access to Store-API using PouchDB</h1>
<content></content>
</body>
<script src="//cdn.jsdelivr.net/pouchdb/5.1.0/pouchdb.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script>
var db = new PouchDB('https://subkitsupport.service.subkit.io/store', {
ajax: {
headers: { 'x-subkit-key': '<%= locals.apikey %>' },
withCredentials: false
}
});
db.allDocs({include_docs: true, descending: true}, updateView);
function updateView(err, doc){
if(err) return $('content').text(err.message);
doc.rows.forEach(function(row){
$('content').append('<h2>' + row.id + '</h2><div>' + JSON.stringify(row.doc) + '</div>');
});
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment