list(query){ query = query || { }; let records = this._table.find(query); // convert loki objects to database-agnostic objects return Store._convertAll(records); }
function initDb() { if (!db.getCollection(config.DB_COLLECTION_MAIN)) { db.addCollection(config.DB_COLLECTION_MAIN) } notebooks = db.getCollection(config.DB_COLLECTION_MAIN) }
// Send data to a specified client function unicast(data, id){ var res = clients.findOne({id}); send_var(data, res.port, res.address); }
/** * 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)); }); }
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')); });
// Send data to every channel function broadcast(data, id){ var res = clients.where((o)=>o.id != id); for(var i=0;i<res.length;i++){ send_var(data, res[i].port, res[i].address); } }
update(object){ let existingRecord = this._table.get(parseInt(object.id)); if (!existingRecord) return; for (let property in object){ // id is an artificial property added on returned objects only, so do not persist it if (property === 'id') continue; existingRecord[property] = object[property]; } this._table.update(existingRecord); }
// Send data to a specified channel function multicast(data, id, channel){ var res = clients.find({channel, id: {'$ne' : id}}); for(var i=0;i<res.length;i++){ send_var(data, res[i].port, res[i].address); } }
srv.before('CREATE', 'Media', req => { const obj = mediaDB.insert({ media: '' }) req.data.id = obj.$loki })
add(object){ let record = this._table.insert(object); return Store._convert(record); }
put(joke) { return tidyResult( this.jokes.insert(joke) ); }