-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checking if a key exists #233
Comments
See Level/community#106 (and give it a thumbs up). PS. The referenced #156 (comment) is for checking whether the db is empty, rather than checking whether a key exists. As for |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was surprised to find that
level
does not have ahas
function to check if a key exists in the database.Map
has ahas
function.localStorage.getItem
returnsundefinednull.level
throws a "Key not found error".Checking if a key exists is a common thing to do when initializing values in a key-value store.
Currently I put
db.get
in a try-catch, but that feels awkward. The solutions suggested in #156 (comment) are counter-intuitive.So out of curiosity, why not have a
db.has
function, or returnnull
fromdb.get
?The text was updated successfully, but these errors were encountered: