kriszyp / lmdb-js

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

Add `putBinary` equivalent for `getBinary`? #95

Closed KyleAMathews closed 2 years ago

KyleAMathews commented 2 years ago

Thinking through how to build replication on top of LMDB — getBinary would be great for cheaply copying data over the network. It'd be great if there was an equivalent putBinary for inserting the buffers at the replicant.

kriszyp commented 2 years ago

In v2.0 you can do this with asBinary https://github.com/DoctorEvidence/lmdb-store/commit/4d2e54a92accc4b2cb7c3bdaa63bb9701b2ac99b#diff-af95cb6f5f65fe70216ddce70325e785438d5aaff956a0666ebf46ef6402f526R262 like:

import { asBinary } from 'lmdb';
db.put(key, asBinary(buffer));

I did this with a marker function since there are actually several places you might want to provide direct binary values: put, putSync, batch#put, and doesExist (and didn't want to create *Binary equivalents of all of them).

I could backport this, but v2.0 will be ready pretty soon (probably this week), and I think it is pretty backwards compatible.

KyleAMathews commented 2 years ago

Ah nifty that looks perfect! No need to backport as I'm sure we'll upgrade before worrying about replication.