You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was surprised to find that level does not have a has function to check if a key exists in the database. Map has a has function. localStorage.getItem returns undefined null. 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 return null from db.get?
The text was updated successfully, but these errors were encountered:
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.
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: