How to use the lokijs 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 Emensionyu / qm_lesson / react / react-notes / src / database / index.js View on Github external
import Loki from 'lokijs'
// db 句柄
export const db = new Loki('notes',{
  autoload:true,
  autoloadCallback:databaseInitialize,
  autosave:true,
  autosaveInterval:3000,
  persistenceMethod:'localStorage'
});
function databaseInitialize() {
  const notes = db.getCollection('notes');
  if(notes == null){
    db.addCollection('notes');
  }
}
export function loadCollection(collection){
  return new Promise((resolve)=>{
    db.loadDatabase({},()=>{
      const _collection =
github catamphetamine / webpack-react-redux-server-side-render-example / api / custom / initialize.js View on Github external
function $initialize() {
	const database = new loki('database.json')
	global.database = database
	global.loadDatabase = function() {
		return new Promise(resolve => database.loadDatabase({}, resolve))
	}
}
github jsdelivr / api / db / index.js View on Github external
import _ from 'lodash';
import Loki from 'lokijs';
import config from '../config';

let db = {
	db: new Loki(config.db),
	v1Schema: {
		name: '',
		mainfile: '',
		lastversion: '',
		description: '',
		homepage: '',
		github: '',
		author: '',
		versions: [],
		assets: {},
		meta: {},
	},
	etagsSchema: {
		cdn: '',
	},
};
github virtool / virtool / client / src / js / dispatcher / database.js View on Github external
return new Promise ((resolve, reject) => {

            this.lokiAdapter = new LokiIndexedAdapter(`virtool-${dispatcher.settings.get("server_id")}`);

            window.lokiAdapter = this.lokiAdapter;

            this.loki = new Loki(null, {
                env: "BROWSER",
                autosave: true,
                adapter: this.lokiAdapter
            });

            this.loki.loadDatabase({}, (err) => {
                if (err) {
                    reject();
                } else {
                    forIn(DEFINITIONS, (definition, collectionName) => {
                        let collection = this.loki.getCollection(collectionName);

                        if (!collection) {
                            collection = this.loki.addCollection(collectionName, {
                                unique: definition.unique,
                                indices: definition.indices
github Azure / Azurite / src / common / persistence / LokiExtentMetadataStore.ts View on Github external
public constructor(public readonly lokiDBPath: string) {
    this.db = new Loki(lokiDBPath, {
      autosave: true,
      autosaveInterval: 5000
    });
  }
github howtocards / frontend / mock-server / server / models / index.js View on Github external
return Future((reject, resolve) => {
    db = new Loki("/tmp/howtocards.db", {
      verbose: true,
      autoload: true,
      autoloadCallback: databaseInitialize(reject, resolve),
      autosave: true,
      autosaveInterval: 1000,
    })
  })
}
github Azure / Azurite / src / LokiBlobMetadataStore.ts View on Github external
public constructor(public readonly lokiDBPath: string) {
    this.db = new Loki(lokiDBPath, {
      autosave: true,
      autosaveInterval: 5000
    });
  }
github RocketChat / Rocket.Chat / packages / rocketchat-lib / server / models / _BaseCache.js View on Github external
stats.push([Math.round(target._stats[property].avg*100)/100, property]);
			}
		}
		return _.sortBy(stats, function(record) {
			return record[0];
		});
	};
}

class Adapter {
	loadDatabase(/*dbname, callback*/) {}
	saveDatabase(/*dbname, dbstring, callback*/) {}
	deleteDatabase(/*dbname, callback*/) {}
}

const db = new loki('rocket.chat.json', {adapter: Adapter});

class ModelsBaseCache extends EventEmitter {
	constructor(model) {
		super();

		traceMethodCalls(this);

		this.indexes = {};
		this.ignoreUpdatedFields = ['_updatedAt'];

		this.query = {};
		this.options = {};

		this.ensureIndex('_id', 'unique');

		this.joins = {};