How the LMDB entities work together
masterLMDB is organized into four main entities that follow a specific hierarchy:
Env(Environment): Represents the full database environment. AnEnvobject must be used by only one process, but can be used by multiple threads. You mustopen()it before use andclose()it when finished.Dbi(Database): A sub-database within anEnv. An environment can contain multiple named databases or one unnamed database (usingnullas the name).Txn(Transaction): The basic unit of work. Only one write transaction can be open in an environment at a time.env.beginTxn()will block until the previous write transaction iscommit()ed orabort()ed. ATxnobject must only be accessed by one thread at a time.Cursor: Used to iterate through multiple keys within a specificDbi.
var lmdb = require('node-lmdb');
// 1. Create and open Environment
var env = new lmdb.Env();
env.open({ path: './mydata', mapSize: 2*1024*1024*1024, maxDbs: 3 });
// 2. Open a Database
var dbi = env.openDbi({ name: 'myDb', create: true });
// 3. Use a Transaction
var txn = env.beginTxn();
txn.putString(dbi, 'key', 'value');
txn.commit();
// 4. Cleanup
dbi.close();
env.close();