Support for mdb_cursor_put()
Any plans to add support for mdb_cursor_put()? It should be more efficient along with MDB_CURRENT option in case when you need to perform read-modify-update operation.
@degifted Sure, can you give me an example use case?
Imagine that you have to modify some values in a big table. Currently you have to iterate over the table and alter desired values by putString() method. But this would require additional unnecessary lookup which can be quite costly. Having cursor.setCurrentString() would eliminate that lookup.
@degifted Taking a look at mdb_cursor_put it should be quite easy to wrap it. I'll take a look and have a go at it next week.
@Venemo In the meanwhile I implemented quick and dirty method which addresses my needs
NAN_METHOD(CursorWrap::putUInt32) {
Nan::HandleScope scope;
CursorWrap *cw = Nan::ObjectWrap::Unwrap<CursorWrap>(info.This());
uint32_t value = Nan::To<v8::Number>(info[0]).ToLocalChecked()->Value();
MDB_val data;
data.mv_size = sizeof(uint32_t);
data.mv_data = &value;
unsigned int flags = MDB_CURRENT;
int rc = mdb_cursor_put(cw->cursor, &(cw->key), &data, flags);
if (rc == MDB_NOTFOUND) {
return info.GetReturnValue().Set(Nan::Null());
}
else if (rc != 0) {
return Nan::ThrowError(mdb_strerror(rc));
}
}