Venemo/node-lmdb

Get() Should accept a default value to be returned when key is not found

KrishnaPG opened this issue · 2 comments

node-lmdb/src/txn.cpp

Lines 197 to 199 in 0f2f2e7

if (rc == MDB_NOTFOUND) {
return info.GetReturnValue().Set(Nan::Null());

When the key is not found, currently the code always returns null. It should accept a default value to be returned, instead, when the given key is not found. For example:

get(key, defVal) {
  if(key is not found) return defVal;
}

If you desire a default value, you can use JavaScript.

var value = txn.getString(dbi, 42) || "Your default value"

I don't think it's a good idea to bloat node-lmdb with such features, but if you feel like implementing it, a pull request is always welcome.

I hope the answer I provided is clear. I'm closing this issue now due to lack of response from the OP.