Skip to content

Instantly share code, notes, and snippets.

@substack substack/data.json
Created Jul 31, 2013

Embed
What would you like to do?
failing use of level-search
[
{ "type": "commit", "id": 444, "hash": "6eba8e6a2927a5d8b748d422ad7e64b977ab4f94", "time": 1374904364802 },
{ "type": "output", "job": 444, "data": "beep ", "time": 1374904288007 },
{ "type": "output", "job": 444, "data": "boop.", "time": 1374904289854 },
{ "type": "commit", "id": 555, "hash": "5c825a710662cab0b8abb37132cae19d0dcf00cb", "time": 1374904278950 },
{ "type": "output", "job": 555, "data": "hello ", "time": 1374904366509 },
{ "type": "output", "job": 555, "data": "world!", "time": 1374904367169 }
]
substack : example $ node fail.js
[ 'type', 'commit' ]
/home/substack/projects/level-join/node_modules/level-search/index.js:146
return key[key.length - 1];
^
TypeError: Cannot read property 'length' of undefined
at /home/substack/projects/level-join/node_modules/level-search/index.js:146:23
at /home/substack/projects/level-join/node_modules/level-search/node_modules/pull-stream/throughs.js:150:15
at /home/substack/projects/level-join/node_modules/level-search/node_modules/pull-stream/throughs.js:85:19
at /home/substack/projects/level-join/node_modules/level-search/node_modules/pull-stream/throughs.js:15:7
at /home/substack/projects/level-join/node_modules/level-search/node_modules/pull-stream/throughs.js:15:7
at drain (/home/substack/projects/level-join/node_modules/level-search/node_modules/pull-level/node_modules/stream-to-pull-stream/index.js:117:18)
at ReadStream.<anonymous> (/home/substack/projects/level-join/node_modules/level-search/node_modules/pull-level/node_modules/stream-to-pull-stream/index.js:126:5)
at ReadStream.EventEmitter.emit (events.js:95:17)
at ReadStream.s.emit (/home/substack/projects/level-join/node_modules/level-sublevel/sub.js:163:14)
at ReadStream._onData (/home/substack/projects/level-join/node_modules/level/node_modules/levelup/lib/read-stream.js:140:8)
var sub = require('level-sublevel');
var through = require('through');
var db = sub(require('level')(__dirname + '/db', { valueEncoding: 'json' }));
var search = require('level-search')(db, 'index');
db.batch(require('./data.json').map(function (row) {
var key = Math.random().toString(16).slice(2);
return { type: 'put', key: key, value: row };
}), ready);
function ready () {
search.createSearchStream([ 'type', 'commit' ])
.pipe(through(function (row) {
console.dir(row);
}))
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.