Level / abstract-level

Abstract class for a lexicographically sorted key-value database.
MIT License
123 stars 8 forks source link

Support a db.has(key) method for testing whether a key exists in the database #66

Closed aaclayton closed 1 year ago

aaclayton commented 1 year ago

For context, I am using https://github.com/Level/classic-level/ but I decided to create this issue here because it should have value for all implementations.

Currently the best available method to test whether a record exists within the database for a particular key is to read the full value of the record using await db.get(key). You can instead iterate over db.keys(), but this is much slower.

It would be nice to have a more lightweight (and potentially even faster) method to assert the existence of a specific key like await db.has(key) which would return a boolean for whether a record exists with that key.

vweevers commented 1 year ago

Duplicate of https://github.com/Level/community/issues/106

aaclayton commented 1 year ago

Sorry I did not notice this issue in the other repo backlog. Thanks for the redirect.