kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
481 stars 39 forks source link

doesExist ambiguous? #213

Closed anywhichway closed 1 year ago

anywhichway commented 1 year ago

The doc below seems ambiguous. What if the value at the key is a number?

db.doesExist(key, valueOrVersion): boolean

This checks if an entry exists for the given key, and optionally verifies that the version or value exists. If this is a dupSort enabled database, you can provide the key and value to check if that key/value entry exists. If you are using a versioned database, you can provide a version number to verify if the entry for the provided key has the specific version number. This returns true if the entry does exist.

kriszyp commented 1 year ago

Keys can be numbers, so if you use doesExist with a just a number and no second argument, it will return if there is an entry with that key.

db.putSync(42, {});
db.doesExist(42) -> true
db.doesExist(43) -> false
anywhichway commented 1 year ago

Sorry I was not clear, I should have said "value" not "key". What about this with versioning on:

db.putSync("a",2,1);

db.doesExist("a",2); -> true, because the value 2 exists (2 is a value for valueOrVersion) db.doesExist("a",1); -> true, because the version of "a" is version 1 (1 is a version for valueOrVersion)

then later

db.putSync("a",1,2);

db.doesExist("a",2); -> true, because the version 2 exists (2 is a version for valueOrVersion) db.doesExist("a",1); -> true, because the value of "a" is 1 (1 is a value for valueOrVersion)

kriszyp commented 1 year ago

If you have versioning enabled, it will treat the second argument as a version. So db.doesExist("a",1) would be true for the first example and db.doesExist("a",2); for the second.

anywhichway commented 1 year ago

Thank you.

anywhichway commented 1 year ago

Thank you.