Closed raineorshine closed 1 year ago
See https://github.com/Level/community/issues/106 (and give it a thumbs up). PS. The referenced https://github.com/Level/level/issues/156#issuecomment-527757444 is for checking whether the db is empty, rather than checking whether a key exists.
As for undefined
, see https://github.com/Level/abstract-level/pull/49 (will happen in abstract-level
v2).
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
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 https://github.com/Level/level/issues/156#issuecomment-527757444 are counter-intuitive.So out of curiosity, why not have a
db.has
function, or returnnull
fromdb.get
?