How to use the lokijs.LokiFsAdapter function in lokijs

To help you get started, we’ve selected a few lokijs 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 exoframejs / exoframe-server / src / db / index.js View on Github external
// npm packages
const path = require('path');
const Loki = require('lokijs');

// our packages
const {baseFolder} = require('../config');

// TTL for auth requests
const REQ_TTL =
  process.env.NODE_ENV !== 'testing'
    ? 5 * 60 * 1000 // 5 mins for prod
    : 0; // 0 for tests

// init in-memory adapter for login requests
const memAdapter = new Loki.LokiMemoryAdapter();
const fsAdapter = new Loki.LokiFsAdapter();

// init in-memory requests db
const db = new Loki('requests.db', {adapter: memAdapter, autoload: true});
// init persistent tokens db
let tokenCollection = {};
const tokenDb = new Loki(path.join(baseFolder, 'auth.db'), {
  adapter: process.env.NODE_ENV !== 'testing' ? fsAdapter : memAdapter,
  autoload: true,
  autoloadCallback() {
    // get of create tokens collection
    tokenCollection = tokenDb.getCollection('tokens');
    if (tokenCollection === null) {
      tokenCollection = tokenDb.addCollection('tokens');
    }
  },
  autosave: process.env.NODE_ENV !== 'testing',
github project-flogo / flogo-web / apps / server / src / common / db / db.ts View on Github external
return new Promise(resolve => {
    persistedDb = new Loki(dbPath, {
      adapter: persist ? new Loki.LokiFsAdapter() : new Loki.LokiMemoryAdapter(),
      autoload: true,
      autosave,
      autoloadCallback: afterInitDb(resolve),
      autosaveInterval: 4000,
    });
  });
}