UNPKG

yekonga-server

Version:
40 lines (32 loc) 1.29 kB
var path = serverLibrary.path; var Datastore = serverLibrary.Datastore; module.exports = function(db) { var dbPath = path.join(serverLibrary.__dirname, './assets/database'); var _db = {} if (!db) { db = Yekonga.Schema; } if (Array.isArray(db)) { for (const item of db) { if (item._id && item._id.collection) { _db[item._id.collection] = new Datastore({ filename: `${dbPath}/${item._id.collection}.db`, autoload: true }); } else if (item.path) { _db[item.collection] = new Datastore({ filename: item.path, autoload: true }); } else { _db[item.collection] = new Datastore({ autoload: true, inMemoryOnly: true }); } } } else if (db && typeof db == 'object') { for (const collection in db) { if (db.hasOwnProperty(collection)) { const item = db[collection]; if (item.path) { _db[collection] = new Datastore({ filename: item.path, autoload: true }); } else { _db[collection] = new Datastore({ autoload: true, inMemoryOnly: true }); } } } } return _db };