Level / abstract-leveldown

An abstract prototype matching the leveldown API.
MIT License
146 stars 53 forks source link

Support `for await...of db.iterator()` #379

Closed vweevers closed 3 years ago

vweevers commented 3 years ago

Closes #235. You can now do:

try {
  for await (const [key, value] of db.iterator()) {
    console.log(key)
  }
} catch (err) {
  console.error(err)
}

Supersedes #338, which was just a proof of concept and we've since dropped support of legacy runtimes (Level/community#98) which now allows us to use async generators across the board.

vweevers commented 3 years ago

Might want to add keys and values options before it's too late to change the function signature. We could do:

for await (const key of db.iterator({ values: false }))

But I think I prefer a new API, in which case it's not a blocker:

for await (const key of db.keyIterator())

Or even:

for await (const key of db.keys())
ralphtheninja commented 3 years ago

I prefer the last one.

vweevers commented 3 years ago

7.1.0