Created
November 15, 2013 17:22
-
-
Save Siedrix/7488152 to your computer and use it in GitHub Desktop.
LevelDb examples for ChelaJs #2
This file contains hidden or 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 level = require('level'); | |
| var db = level('./chelajs-demo'); | |
| db.put("foo", "bar", function () { | |
| console.log("foo has been saved"); | |
| }); |
This file contains hidden or 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 level = require('level'); | |
| var db = level('./chelajs-demo'); | |
| db.get('foo', function(err, foo){ | |
| console.log(err, foo); | |
| }); |
This file contains hidden or 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 level = require('level'); | |
| var db = level('./chelajs-demo'); | |
| db.del('foo', function(err, foo){ | |
| console.log('foo has been deleted'); | |
| db.get('foo', function (err, foo) { | |
| console.log(err, foo); | |
| }); | |
| }); |
This file contains hidden or 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 level = require('level'); | |
| var db = level('./chelajs-demo'); | |
| var ops = [ | |
| { type: "del", key: 'foo' }, | |
| { type: "put", key: "rog3r" , value : "hitchhiker’s guide to processing.js"}, | |
| { type: "put", key: "xiam" , value : "javascript tetris"}, | |
| { type: "put", key: "jeduan" , value : "Handlebars"}, | |
| { type: "put", key: "pateketrueke" , value : "Js en Grupo Expansion"}, | |
| { type: "put", key: "Siedrix" , value : "LevelDb"}, | |
| { type: "put", key: "HardBit" , value : "Apps Desktop con nodejs y chromium"}, | |
| { type: "put", key: "JCeb" , value : "desarrollo de bibliotecas javascript, server side y client side"} | |
| ]; | |
| db.batch(ops, function (err) { | |
| if (err) return console.log('Ooops!', err); | |
| console.log('Yei beer and js!'); | |
| }); |
This file contains hidden or 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 level = require('level'); | |
| var db = level('./chelajs-demo'); | |
| setTimeout(function () { | |
| db.createReadStream().on('data', function(data){ | |
| console.log("Got:",data); | |
| }) | |
| .on('end', function(){ | |
| console.log("Finish query"); | |
| }) | |
| .on('error', function(err){ | |
| console.log("There as an error", err); | |
| }); | |
| }, 200); |
This file contains hidden or 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 level = require('level'); | |
| level('./chelajs-demo',{createIfMissing: true}, function (err, db) { | |
| var liveStream = require('level-live-stream')(db); | |
| liveStream.on('data', function(data){ | |
| if(!data.type) return; | |
| console.log('Change on:', process.hrtime()); | |
| console.log(data); | |
| console.log("========================================"); | |
| }); | |
| var ops = [ | |
| { type: "del", key: 'foo' }, | |
| { type: "put", key: "rog3r" , value : "hitchhiker’s guide to processing.js"}, | |
| { type: "put", key: "xiam" , value : "javascript tetris"}, | |
| { type: "put", key: "jeduan" , value : "Handlebars"}, | |
| { type: "put", key: "pateketrueke" , value : "Js en Grupo Expansion"}, | |
| { type: "put", key: "Siedrix" , value : "LevelDb"}, | |
| { type: "put", key: "HardBit" , value : "Apps Desktop con nodejs y chromium"}, | |
| { type: "put", key: "JCeb" , value : "desarrollo de bibliotecas javascript, server side y client side"} | |
| ]; | |
| db.batch(ops, function (err) { | |
| if (err) return console.log('Ooops!', err); | |
| console.log('Done ==> Yei beer and js!'); | |
| }); | |
| }); |
This file contains hidden or 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 level = require('level'); | |
| var Sublevel = require('level-sublevel'); | |
| var db = level('./chelajs-demo'); | |
| db = Sublevel(db); | |
| var js = db.sublevel('js'); | |
| var beer = db.sublevel('beer'); | |
| beer.put('foo','qui'); | |
| beer.put('bar','quz'); | |
| setTimeout(function () { | |
| js.put('foo','bar', function(err){ | |
| beer.createReadStream().on('data', function(data){ | |
| console.log("Got:",data); | |
| }) | |
| .on('end', function(){ | |
| console.log("Finish query"); | |
| }) | |
| .on('error', function(err){ | |
| console.log("There as an error", err); | |
| }); | |
| }); | |
| }, 1000); |
This file contains hidden or 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 level = require('level'); | |
| var Sublevel = require('level-sublevel'); | |
| var db = level('./chelajs-demo', { valueEncoding: 'json' }); | |
| db = Sublevel(db); | |
| var sub = db.sublevel('stuff'); | |
| sub.put('foo', {bar:true}, function (err) { | |
| sub.get('foo', function (err, data) { | |
| console.log(typeof data); | |
| console.log('foo:', data); | |
| }); | |
| }); |
This file contains hidden or 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
| Links used in the presentation. | |
| http://www.w3.org/TR/IndexedDB/ | |
| http://research.google.com/pubs/SanjayGhemawat.html | |
| http://research.google.com/pubs/jeff.html | |
| https://code.google.com/p/leveldb/ | |
| http://basho.com/riak/ | |
| https://npmjs.org/package/level-sublevel | |
| https://github.com/rvagg/node-levelup/wiki/Modules | |
| https://github.com/eugeneware/jsonquery-engine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment