This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
API design: getMany()
, key & value iterators, iterator.nextv()
#380
Labels
enhancement
New feature or request
Comments
The (internals of these) methods can benefit from each other. In
|
👍 for nextv() I’ve implemented this in userland. |
This was referenced Sep 24, 2021
Merged
vweevers
added a commit
to Level/abstract-level
that referenced
this issue
Jan 9, 2022
I'm squeezing this in for similar reasons as #8. I wondered whether these additions would be breaking. The short answer is no. In addition, adding this now means `level-read-stream` can make use of it without conditional code paths based on `db.supports.*`. Ref Level/abstract-leveldown#380 Adds key and value iterators: `db.keys()` and `db.values()`. As a replacement for levelup's `db.create{Key,Value}Stream()`. Example: ``` for await (const key of db.keys({ gte: 'a' }) { console.log(key) } ``` Adds two new methods to all three types of iterators: `nextv()` for getting many items (entries, keys or values) in one call and `all()` for getting all (remaining) items. These methods have functional but suboptimal defaults: `all()` falls back to repeatedly calling `nextv()` and that in turn falls back to `next()`. Example: ``` const values = await db.values({ limit: 10 }).all() ``` Adds a lot of new code, with unfortunately some duplicate code because I wanted to avoid mixins and other forms of complexity, which means key and value iterators use classes that are separate from preexisting iterators. For example, a method like `_seek()` must now be implemented on three classes: `AbstractIterator`, `AbstractKeyIterator` and `AbstractValueIterator`. This (small?) problem extends to implementations and their subclasses, if they choose to override key and value iterators to improve performance. On the flip side, the new methods are supported across the board: on sublevels, with encodings, with deferred open, and fully functional. This may demonstrate one of the major benefits of `abstract-level` over `abstract-leveldown` paired with `levelup`. Yet todo: - [ ] Tests - [ ] Replace use of `level-concat-iterator` in existing tests - [ ] After that, try another approach with a `mode` property on iterators, that is one of entries, keys or values (moving logic to if-branches... I already don't like it but it may result in cleaner logic downstream).
3 tasks
vweevers
added a commit
to Level/abstract-level
that referenced
this issue
Jan 16, 2022
Ref Level/abstract-leveldown#380 Adds key and value iterators: `db.keys()` and `db.values()`. As a replacement for levelup's `db.create{Key,Value}Stream()`. Example: ``` for await (const key of db.keys({ gte: 'a' }) { console.log(key) } ``` Adds two new methods to all three types of iterators: `nextv()` for getting many items (entries, keys or values) in one call and `all()` for getting all (remaining) items. These methods have functional but suboptimal defaults: `all()` falls back to repeatedly calling `nextv()` and that in turn falls back to `next()`. Example: ``` const values = await db.values({ limit: 10 }).all() ```
vweevers
added a commit
to Level/abstract-level
that referenced
this issue
Jan 16, 2022
Ref Level/abstract-leveldown#380 Adds key and value iterators: `db.keys()` and `db.values()`. As a replacement for levelup's `db.create{Key,Value}Stream()`. Example: ``` for await (const key of db.keys({ gte: 'a' }) { console.log(key) } ``` Adds two new methods to all three types of iterators: `nextv()` for getting many items (entries, keys or values) in one call and `all()` for getting all (remaining) items. These methods have functional but suboptimal defaults: `all()` falls back to repeatedly calling `nextv()` and that in turn falls back to `next()`. Example: ``` const values = await db.values({ limit: 10 }).all() ```
Done in Next steps:
|
Repository owner
moved this from Todo
to Done
in Level
Jan 16, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
AbstractIterator
but 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.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 (ofleveldown
) still applies - if either size or hwm is reached then we stop.Options could include
end: true
to automatically end the iterator.iterator.all([options][, callback])
Same as
level-concat-iterator
, but highly optimizable. Inlevel-js
it can also offer snapshot guarantees when we drop that from (regular use of) iterators. No options, that argument is just reserved.The text was updated successfully, but these errors were encountered: