How to use the node-lmdb.Env function in node-lmdb

To help you get started, we’ve selected a few node-lmdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nimiq / jungle-db / src / main / backend / lmdb / JungleDB.js View on Github external
connect() {
        if (this._db) return Promise.resolve(this._db);

        // Ensure existence of directory.
        if (!fs.existsSync(this._databaseDir)){
            fs.mkdirSync(this._databaseDir);
        }

        let numDbs = 1;
        for (const { /** @type {LMDBBackend} */ backend, upgradeCondition } of this._objectStoreBackends) {
            numDbs += 1 + backend.indices.size;
        }

        this._db = new lmdb.Env();
        this._db.open({
            path: this._databaseDir,
            mapSize: this._options.maxDbSize || (1024*1024*5), // 5MB default
            maxDbs: (this._options.maxDbs + 1) || numDbs, // default, always add 1 for the internal db
            useWritemap: this._options.useWritemap || false,
        });

        // Check if resize is needed.
        if (this.autoResize && this.needsResize()) {
            this.doResize();
        }

        this._mainDb = this._db.openDbi({
            name: null,
            create: true
        });
github josephg / sephsplace / server.js View on Github external
const url = require('url')
const WSS = require('ws').Server;
const express = require('express')
const fs = require('fs')

const kclient = new kafka.Client()
const app = express()
const server = require('http').createServer(app)
const wss = new WSS({server, perfMessageDeflate: false})

app.use('/sp', express.static(__dirname + '/public'))

// This is important so we can hot-resume when the server starts without
// needing to read the entire kafka log. A file would almost be good enough,
// but we need to atomically write to it. So, this is easier.
const dbenv = new lmdb.Env()

if (!fs.existsSync('snapshot')) fs.mkdirSync('snapshot')
dbenv.open({ path: 'snapshot', mapSize: 100*1024*1024 })
const snapshotdb = dbenv.openDbi({create: true})


const randInt = max => (Math.random() * max) | 0

const loadSnapshot = () => {
  // Read a snapshot from the database if we can.
  const txn = dbenv.beginTxn({readOnly: true})

  const _version = txn.getNumber(snapshotdb, 'version')
  if (_version != null) {
    const data = txn.getBinary(snapshotdb, 'current')
    assert(data)
github tinkerhub / tinkerhub / lib / storage / index.js View on Github external
constructor(path) {
		debug('Opening storage at ' + path);

		mkdirp.sync(path);

		this._env = new lmdb.Env();
		this._env.open({
			path: path,
		});

		this._db = this._env.openDbi({
			name: 'shared',
			create: true
		});
	}
github polkadot-js / common / packages / db / src / engines / LmDb.ts View on Github external
constructor (base: string, name: string, options?: BaseDbOptions) {
    this._env = new lmdb.Env();
    this._path = path.join(base, name);
    this._rtxn = null;
    this._wtxn = null;

    mkdirp.sync(this._path);

    const dbsize = this.size(true);
    const mapSize = Math.ceil(1 + (dbsize / GB)) * GB;

    l.debug(() => `Current mapsize set to ${(mapSize / GB).toFixed(1)}GB`);

    this._env.open({
      path: this._path,
      mapSize
    });
  }
github peeriodproject / core / src / core / topology / BucketStore.js View on Github external
var openDatabase = function () {
            _this._databaseEnvironment = new lmdb.Env();
            _this._databaseEnvironment.open({
                //name: this._name,
                path: _this._path
            });
        };
github bitpay / bwdb / lib / db.js View on Github external
exports.open = function(dbPath, readOnly) {
  var db = {};
  db.env = new lmdb.Env();
  db.env.open({
    path: dbPath,
    maxDbs: 15,
    mapSize: 268435456 * 4096,
    maxReaders: 126,
    noMetaSync: true,
    noSync: true,
    readOnly: readOnly
  });
  db.addressesMap = db.env.openDbi({
    name: 'addressesMap',
    create: !readOnly
  });
  db.addresses = db.env.openDbi({
    name: 'addresses',
    create: !readOnly

node-lmdb

Node binding for LMDB, the Lightning Memory-Mapped Database

MIT
Latest version published 4 months ago

Package Health Score

73 / 100
Full package analysis

Popular node-lmdb functions