Expose Iterables
See original GitHub issueAdd .keys(), .values() .entries() methods similar to the Map spec but instead they should return a Promise that resolves to an iterable.
Something like:
const keyv = new Keyv();
await keyv.set('foo', 'bar');
await keyv.set('fizz', 'buzz');
const keys = await keyv.keys();
for (const key of keys) {
console.log(key);
}
// 'foo'
// 'fizz'
const values = await keyv.values();
for (const value of values) {
console.log(value);
}
// 'bar'
// 'buzz'
const entries = await keyv.entries();
for (const [key, value] of entries) {
console.log(`${key} => ${value}`);
}
// 'foo => bar'
// 'fizz => buzz'
Issue Analytics
- State:
- Created 6 years ago
- Reactions:22
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Should Iterator or Iterable be used when exposing internal ...
I have a class with a private mutable list of data. I need to expose list items given following conditions: List should not...
Read more >JavaScript Iterators and Iterables - AppSignal Blog
An iterable in JavaScript is an object that defines custom iteration behaviour via a method on itself or any of the objects in...
Read more >Exposed/IterableEx.kt at master · JetBrains/Exposed - GitHub
Kotlin SQL Framework. Contribute to JetBrains/Exposed development by creating an account on GitHub. ... interface SizedIterable<out T> : Iterable<T> {.
Read more >Iterators, Iterables and Itertools - Finxter
Now let's expose what's going on inside. First, let's look at the methods that l provides (the dir function lists the methods of...
Read more >Demystifying ES6 Iterables & Iterators - freeCodeCamp
Let's demystify it. There are 2 core concepts: Iterable — described by a data structure that provides a way to expose its data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This worked for me:
keyv.opts.store.query('SELECT key FROM keyv;');Edit: Changed from querying all to just the key. Thanks to HunteRoi.
This requires all of the values to be slurped (or slurpable) before each method resolves, potentially incurring a huge cost in time and memory. What if there are a million records in a remote backend — taking, say, a minute to retrieve, and chewing through a gig of (mobile) RAM — but the caller only needs to check the first two?
It would be more efficient to wait for a result, then process it, then wait for another result, then process that etc. The usual way to do this is not with a recordset (e.g. a promise which returns an array) but with a cursor (e.g. an async iterator):
While consuming them in this way requires ES2018 (or Babel or TypeScript), producing them does not (just as any library can spit out promises for consumption by async/await). And, of course, the desugared usage is always available as a fallback: