function initDb() { if (!db.getCollection(config.DB_COLLECTION_MAIN)) { db.addCollection(config.DB_COLLECTION_MAIN) } notebooks = db.getCollection(config.DB_COLLECTION_MAIN) }
constructor() { this.jokes = db.addCollection('jokes', { indices: ['id'] }); this.jokes.insert( { id : '1', value : 'my mother in law' } ); this.jokes.insert( { id : '2', value : 'an englishman an irishman and a scotsman' } ); }
db.loadDatabase({}, () => { resolve(db.getCollection('users')); });
/** * Init DB. * @returns {Promise<unknown>} */ async function init() { log.info(`Init DB (${configuration.path}/${configuration.file})`); if (!fs.existsSync(configuration.path)) { log.debug(`Create folder ${configuration.path}`); fs.mkdirSync(configuration.path); } return new Promise((resolve, reject) => { db.loadDatabase({}, (err) => loadDb(err, resolve, reject)); }); }
/** * Load DB. * @param err * @param resolve * @param reject * @returns {Promise<void>} */ async function loadDb(err, resolve, reject) { if (err) { reject(err); } else { images = db.getCollection('images'); if (images === null) { log.info('DB empty => Create DB Collections'); images = db.addCollection('images'); } resolve(); } }
const initDb = (app) => { const databaseInitialize = () => { /* eslint-disable no-use-before-define */ let registeredClaims = db.getCollection('registeredClaims'); if (registeredClaims === null) { registeredClaims = db.addCollection('registeredClaims'); } /* eslint-enable no-use-before-define */ app.set('registeredClaims', registeredClaims); }; const db = new Loki('loki.json', { autoload: true, autoloadCallback: databaseInitialize, autosave: true, autosaveInterval: 4000, }); }
this.database.loadDatabase({}, function(err){ }.bind(this)); } else { this._table = this.database.addCollection(table, keys); if (onReady) onReady(this);