-
Notifications
You must be signed in to change notification settings - Fork 80
/
db.js
29 lines (27 loc) · 848 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const NeDbClient = require('./clients/nedbclient');
const MongoClient = require('./clients/mongoclient');
/**
* Connect to current database
*
* @param {String} url
* @param {Object} options
* @returns {Promise}
*/
exports.connect = function(url, options) {
if (url.indexOf('nedb://') > -1) {
// url example: nedb://path/to/file/folder
return NeDbClient.connect(url, options).then(function(db) {
global.CLIENT = db;
return db;
});
} else if(url.indexOf('mongodb://') > -1) {
// url example: 'mongodb://localhost:27017/myproject'
return MongoClient.connect(url, options).then(function(db) {
global.CLIENT = db;
return db;
});
} else {
return Promise.reject(new Error('Unrecognized DB connection url.'));
}
};