Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ posts.put('1337', {
start: 10,
end: 20
}).on('data', console.log.bind(console, 'read'))
// => read { key: '1337', value: { id: '1337', title: 'a title', body: 'lorem ipsum' } }

// => read { key: '1337', indexKey: '11!1337', value: { id: '1337', title: 'a title', body: 'lorem ipsum' } }
posts.byLength.createKeyStream({
start: 10,
end: 20
Expand Down Expand Up @@ -128,7 +128,7 @@ Get the value that has been indexed with `key`.

### AutoIndex#create{Key,Value,Read}Stream(opts)

Create a readable stream that has indexes as keys and indexed data as values.
Create a readable streams. The order of entries matches the ordering of the indices. Keys and values are taken from the underlying level. If both `key` and `value` are requested, the entries will contains another field `indexKey`, which contains the index key for that entry.

### AutoIndex#manifest

Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ posts.put('1337', {
start: 10,
end: 20
}).on('data', console.log.bind(console, 'read'))
// => read { key: '1337', value: { id: '1337', title: 'a title', body: 'lorem ipsum' } }
// => read { key: '1337', indexKey: '11!1337', value: { id: '1337', title: 'a title', body: 'lorem ipsum' } }

posts.byLength.createKeyStream({
start: 10,
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function AutoIndex (db, idb, reduce, opts) {
} else {
done(null, {
key: dbKey,
indexKey: idbKey,
value: value
})
}
Expand Down
6 changes: 6 additions & 0 deletions test/multi-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ test('multi-key index', function (t) {
function handleResults (data) {
t.equal(data.length, 3)
t.equal(data[0].key, '0')
t.equal(data[0].indexKey, 'foo!0')
t.deepEqual(data[0].value, postData[0])
t.equal(data[1].key, '20')
t.equal(data[1].indexKey, 'foo!20')
t.deepEqual(data[1].value, singlePost)
t.equal(data[2].key, '3')
t.equal(data[2].indexKey, 'foo!3')
t.deepEqual(data[2].value, postData[3])
posts.del(3, function (err) {
t.error(err)
Expand All @@ -97,8 +100,11 @@ test('multi-key index', function (t) {
tagIndexStream.pipe(concatStream)
function handleResults (data) {
t.equal(data.length, 2)
t.equal(data[0].key, '0')
t.equal(data[0].indexKey, 'foo!0')
t.deepEqual(data[0].value, postData[0])
t.equal(data[1].key, '20')
t.equal(data[1].indexKey, 'foo!20')
t.deepEqual(data[1].value, singlePost)
t.end()
}
Expand Down
1 change: 1 addition & 0 deletions test/read-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('read streams', function (t) {
}).on('data', function (data) {
t.deepEqual(data, {
key: '1337',
indexKey: '11',
value: post
})
})
Expand Down