TreeDB
LevelDB backend for hierarchical data.
Store
Storing an object:
var db = '/tmp/treedb';var tree = db;tree;
Output:
[ 'person', 'WkvBeQ1yB' ]
Query
Query all person types:
var path = ;var db = '/tmp/treedb';var tree = db;var people = ;tree // returns a readable stream;
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 theobj
cb
- 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 treedb
License
MIT