0.1.0 • Published 11 years ago
treedb v0.1.0
TreeDB
LevelDB backend for hierarchical data.
Store
Storing an object:
var db = require('levelup')('/tmp/treedb');
var tree = require('treedb')(db);
tree.store({
type: 'person',
name: 'Foo Bar',
slogan: 'hello world'
}, function(err, val) {
console.log(val);
});Output:
[ 'person', 'WkvBeQ1yB' ]Query
Query all person types:
var path = require('path');
var db = require('levelup')('/tmp/treedb');
var tree = require(path.join(__dirname, '..'))(db);
var people = [];
tree.nodes('person') // returns a readable stream
.on('data', function(person) {
people.push(person);
})
.on('end', function() {
console.log(people);
});Output:
[ { key: [ 'person', 'WkvBeQ1yB' ],
value: { type: 'person', name: 'Foo Bar', slogan: 'hello world' } } ]Methods
var tree = require('treedb')(db)
Create a new treedb from a leveldb handle db and set it to the tree handle.
tree.store(obj, parentKey, cb)
If parentKey is null, the obj that is stored will be a top level object.
obj- object to storeparentKey- key of the parent object of theobjcb- callback function that is called withfunction(err, obj)
var rstream = tree.nodes(type, opts)
Return a readable object stream rstream with the contents of the nodes of the given type. - type - the type of the node as a string - opts - options object - indexedField - field to sort by
var rstream = tree.children(key, opts)
tree.addIndex(type, field, cb)
tree.addSecondaryIndex(type, parentType, field, cb)
Install
npm install treedbLicense
MIT
0.1.0
11 years ago