Last active
August 29, 2015 14:06
-
-
Save nolanlawson/8f58dbc360348a4c95f6 to your computer and use it in GitHub Desktop.
Bulk put and bulk get kitties in date order
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
// 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({ | |
_id: new Date().toJSON(), | |
name: 'Mittens', | |
occupation: 'kitten', | |
cuteness: 9.0 | |
}).then(function () { | |
return db.put({ | |
_id: new Date().toJSON(), | |
name: 'Katie', | |
occupation: 'kitten', | |
cuteness: 7.0 | |
}); | |
}).then(function () { | |
return db.put({ | |
_id: new Date().toJSON(), | |
name: 'Felix', | |
occupation: 'kitten', | |
cuteness: 8.0 | |
}); | |
}).then(function () { | |
return db.allDocs({include_docs: true}); | |
}).then(function (result) { | |
var display = document.getElementById('display'); | |
display.innerHTML = 'We got some kitties! And they\'re sorted!' + | |
'\nKitty 1: ' + JSON.stringify(result.rows[0].doc) + | |
'\nKitty 2: ' + JSON.stringify(result.rows[1].doc) + | |
'\nKitty 3: ' + JSON.stringify(result.rows[2].doc); | |
}).catch(function (err) { | |
console.log(err); | |
}); | |
// | |
// IMPORTANT CODE ENDS HERE | |
// | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment