Jotting down thoughts about various feature requests, ideas and perf improvements - and how APIs for those could fit together.
db.getMany(keys[, options][, callback])
assert(db.supports.getMany)
for (const value of await db.getMany(['a', 'b']) {
// value may be undefined
}
keyIterator = db.keys([options])
Inherits from AbstractIterator but yields keys instead of entries. Similar to db.createKeyStream() but without the overhead of streams (also in terms of browser bundle size; we might want to move streams to userland because they operate on iterators anyway, and you could potentially choose between readable-stream, core stream, streamx, pull stream).
assert(db.supports.keyIterators)
for await (const key of db.keys({ limit: 2, reverse: true }))
valueIterator = db.values([options])
assert(db.supports.valueIterators)
for await (const value of db.values({ gte: 'foo' }))
iterator.mode
A property by which consumers (like streams) can determine what results to expect. One of entries, keys, values.
iterator.nextv(size[, options][, callback])
Useful for optimized streams, but also just getting X entries. The highWaterMark option (of leveldown) still applies - if either size or hwm is reached then we stop.
const entries = await iterator.nextv(60) // [['key', 'value'], ...]
const keys = await keyIterator.nextv(60) // ['key', ...]
const values = await valueIterator.nextv(60) // ['value', ...]
Options could include end: true to automatically end the iterator.
const first = await iterator.nextv(1, { end: true })[0]
iterator.all([options][, callback])
Same as level-concat-iterator, but highly optimizable. In level-js it can also offer snapshot guarantees when we drop that from (regular use of) iterators. No options, that argument is just reserved.
// Same return type as db.getMany() but operating on a range
const array = await db.values({ gte: 'foo', limit: 1e3 }).all()
Jotting down thoughts about various feature requests, ideas and perf improvements - and how APIs for those could fit together.
db.getMany(keys[, options][, callback])keyIterator = db.keys([options])Inherits from
AbstractIteratorbut yields keys instead of entries. Similar todb.createKeyStream()but without the overhead of streams (also in terms of browser bundle size; we might want to move streams to userland because they operate on iterators anyway, and you could potentially choose between readable-stream, core stream, streamx, pull stream).valueIterator = db.values([options])iterator.modeA property by which consumers (like streams) can determine what results to expect. One of
entries,keys,values.iterator.nextv(size[, options][, callback])Useful for optimized streams, but also just getting X entries. The
highWaterMarkoption (ofleveldown) still applies - if either size or hwm is reached then we stop.Options could include
end: trueto automatically end the iterator.iterator.all([options][, callback])Same as
level-concat-iterator, but highly optimizable. Inlevel-jsit can also offer snapshot guarantees when we drop that from (regular use of) iterators. No options, that argument is just reserved.