kriszyp / lmdb-js

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

Guidance on using sharedStructureKey #32

Closed kylebernhardy closed 3 years ago

kylebernhardy commented 3 years ago

Hi,

I wanted to get some guidance on how best to utilize the sharedStructureKey. Is it recommended to define this setting just on environment creation or on each dbi? If it is recommended for each dbi in the environment should each dbi have a unique Symbol?

Thank you for your help!

kriszyp commented 3 years ago

This needs to be defined on each database (in open and openDB) that wants to use the share structures. The unique symbol is for the key that will go in that database, so every database can use the same key (since the entry will be stored in each separate db). We use Buffer.from([1, 10]) in our app (for all dbs), and the docs suggest Symbol.for('structures').

So for example, if you created an env:

let rootStore = open('foo', { sharedStructuresKey: Symbol.for('structures') }); // create env and use root db of env
let otherStore = rootStore.openDB('bar', { sharedStructuresKey: Symbol.for('structures') }); // use the bar database in that same env
kylebernhardy commented 3 years ago

Thank you Kris.