Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 =
function $initialize() {
const database = new loki('database.json')
global.database = database
global.loadDatabase = function() {
return new Promise(resolve => database.loadDatabase({}, resolve))
}
}
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: '',
},
};
constructor(path) {
this.db = new loki(path);
}
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
public constructor(public readonly lokiDBPath: string) {
this.db = new Loki(lokiDBPath, {
autosave: true,
autosaveInterval: 5000
});
}
return Future((reject, resolve) => {
db = new Loki("/tmp/howtocards.db", {
verbose: true,
autoload: true,
autoloadCallback: databaseInitialize(reject, resolve),
autosave: true,
autosaveInterval: 1000,
})
})
}
public constructor(public readonly lokiDBPath: string) {
this.db = new Loki(lokiDBPath, {
autosave: true,
autosaveInterval: 5000
});
}
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 = {};