Level / level

Universal abstract-level database for Node.js and browsers.
MIT License
1.55k stars 106 forks source link

Recommended way of retrieving a list of all keys? #220

Closed faustbrian closed 2 years ago

faustbrian commented 2 years ago

Been wondering what's the recommended way of getting a list of all keys in a database. I'm currently doing the following:

const result = [];

for await (const [key, _] of database.iterator({ keys: true, values: false })) {
    result.push(key);
}

return result;

This feels a bit hacky. Is there any way to do this more efficiently or dump all keys at once?

vweevers commented 2 years ago
const result = await db.keys().all()