Last active
May 18, 2018 08:43
-
-
Save nolanlawson/c02bba75247012afb1bf to your computer and use it in GitHub Desktop.
Putting a kitten
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
<html> | |
<body> | |
<pre id="display"></pre> | |
<script src="//cdn.jsdelivr.net/pouchdb/latest/pouchdb.min.js"></script> | |
<script src="index.js"></script> | |
</body> | |
</html> |
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
var doc = { | |
"_id": "mittens", | |
"name": "Mittens", | |
"occupation": "kitten", | |
"age": 3, | |
"hobbies": [ | |
"playing with balls of yarn", | |
"chasing laser pointers", | |
"lookin' hella cute" | |
] | |
}; | |
// Destroy the database before doing anything, because I want | |
// you to see the same thing if you reload. | |
// Ignore the man behind the curtain! | |
new PouchDB('sample').destroy().then(function () { | |
return new PouchDB('sample'); | |
}).then(function (db) { | |
// | |
// IMPORTANT CODE STARTS HERE | |
// | |
db.put(doc).then(function () { | |
return db.get('mittens'); | |
}).then(function (doc) { | |
document.getElementById('display').innerHTML = 'We stored a kitten: ' + JSON.stringify(doc); | |
}); | |
// | |
// IMPORTANT CODE ENDS HERE | |
// | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment