Skip to content

Commit 99124a6

Browse files
committed
Intro to LevelDB
1 parent 63ce040 commit 99124a6

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

intro-to-leveldb/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Intro to LevelDB
2+
3+
> [https://www.youtube.com/watch?v=sR7p_JbEip0](https://www.youtube.com/watch?v=sR7p_JbEip0)
4+
5+
Install [io.js](https://iojs.org/en/index.html) or [node.js](https://nodejs.org/).
6+
7+
Within this folder run the terminal command `npm install` to install the
8+
`dependencies` and `devDependencies`.
9+
10+
Then run `npm start` to run the app and `http://localhost:9966` to view.

intro-to-leveldb/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var levelup = require('levelup')
2+
var sublevel = require('level-sublevel')
3+
4+
var db = sublevel(levelup('./db', {
5+
db: require('leveldown'),
6+
valueEncoding: 'json'
7+
}))
8+
9+
var bearsdb = db.sublevel('bears')
10+
var regionsdb = db.sublevel('regions')
11+
12+
// regionsdb.put('northamerica', { name: 'North America' }, function (err) {
13+
// bearsdb.put('steve', { type: 'grizzly', region: 'northamerica' }, function () {
14+
//
15+
// })
16+
// })
17+
18+
var bears = []
19+
var stream = bearsdb.createReadStream()
20+
stream.on('data', function (bear) {
21+
regionsdb.get(bear.value.region, function (err, region) {
22+
bear.value.region = region
23+
bears.push(bear.value)
24+
})
25+
})
26+
stream.on('close', function () {
27+
console.log(bears)
28+
})

intro-to-leveldb/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "intro-to-leveldb",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js",
8+
"test": "node test.js"
9+
},
10+
"browser": {
11+
"leveldown": "level-js"
12+
},
13+
"author": "Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)",
14+
"license": "MIT",
15+
"devDependencies": {
16+
"budo": "^4.2.1"
17+
},
18+
"dependencies": {
19+
"level": "^1.3.0",
20+
"level-js": "^2.2.2",
21+
"level-sublevel": "^6.5.1",
22+
"leveldown": "^1.4.1",
23+
"levelup": "^1.2.1"
24+
}
25+
}

0 commit comments

Comments
 (0)