Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created July 24, 2014 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/b5f5a776e253c6aec63e to your computer and use it in GitHub Desktop.
Save nolanlawson/b5f5a776e253c6aec63e to your computer and use it in GitHub Desktop.
PouchDB storage size comparison script
var PouchDB = require('pouchdb');
var NUM_DOCS = 1000;
var dbName = 'after';
//var dbName = 'before';
var pouch = new PouchDB(dbName + '_' + NUM_DOCS);
var text =
"Twas brillig and the slithy toves did gyre and gimble in the wabe. " +
"All mimsy were the borogoves and the mome wraths outgrabe. " +
"Beware the jabberwock, my son - the jaws that bite, the claws that catch! " +
"Beware the jubjub bird, and shun the frumious bandersnatch. " +
"He took his vorpal sword in hand, longtime the manxome foe he sought. " +
"So rested he by the tumtum tree and stood awhile in thought. " +
"And as in uffish thought he stood, the jabberwock with eyes aflame. " +
"Came whiffling through the tulgy wood and burbled as it came.";
var docs = [];
for (var i = 0; i < NUM_DOCS; i++) {
docs.push({text: text});
}
pouch.bulkDocs(docs).then(function () {
return pouch.put({
_id: "_design/words",
views: {
words: {
map: function (doc) {
doc.text.split(/\s+/).forEach(function (word) {
if (word) {
emit(word);
}
});
}.toString()
}
}
})
}).then(function () {
return pouch.query('words', {limit: 1, key: 'tulgy'});
}).then(function (res) {
console.log(JSON.stringify(res));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment