How to use the lokijs.persistenceAdapters 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 andreafeccomandi / bibisco / bibisco / app / adapters / lokijs / loki-fs-sync-adapter.js View on Github external
return (function() {

    var Loki = require('lokijs');

    function LokiFsSyncAdapter() {
      this.fs = require('fs');
    }

    Object.assign(LokiFsSyncAdapter.prototype, Loki.persistenceAdapters
      .fs.prototype, {
      loadDatabase: function(dbname, callback) {
        var err = null;
        var stats;
        stats = this.fs.statSync(dbname);
        if (!err && stats && stats.isFile()) {
          // readFileSync() is the synchronous alternative to async readFile() which loki normally uses
          var data = this.fs.readFileSync(dbname, {
            encoding: 'utf8'
          });
          callback(data);
        } else if (!stats.isFile()) {
          throw new Error(dbname + ' is not a file!');
        } else {
          throw new Error('Error loading db');
        }
github kpiwko / jira-miner / lib / db / client.js View on Github external
var DB = function(path) {

  // create a Loki.js instance with filesystem storega in particular path
  const db = new ExtendedLoki(path, {
    adapter: new Loki.persistenceAdapters.fs()
  })

  return new Promise((resolve, reject) => {
    db.loadDatabase({}, (err, _) => {
      if(err) {
        logger.warn('Unable to load database, ignoring', {path, err})
        return resolve(db)
      }
      logger.debug('Database loaded', {path})
      return resolve(db)
    })
  })

}