#!/usr/bin/env node var level = require('level'); var sublevel = require('subleveldown'); var rawdb = level('/tmp/raw'); var db = sublevel(rawdb, 'd', {valueEncoding: 'json'}); var idb = sublevel(rawdb, 'i'); var treeIndexer = require('../index.js'); var tree = treeIndexer(db, idb); function fail(err) { console.error(err); process.exit(0); } /* Builds the structure: foo --bar ----baz --cat and then gets a stream of the child-paths of foo */ db.put('1', {name: "foo"}, function(err) { if(err) fail(err); db.put('2', {parentKey: '1', name: "bar"}, function(err) { if(err) fail(err); db.put('3', {parentKey: '2', name: "baz"}, function(err) { if(err) fail(err); db.put('4', {parentKey: '1', name: "cat"}, function(err) { if(err) fail(err); console.log("added data"); // wait for index to finish building setTimeout(function() { // get children of foo tree.children('foo', function(err, children) { if(err) fail(err); console.log('children:', children) }); }, 500); }); }); }); })