UNPKG

848 BJavaScriptView Raw
1'use strict';
2
3const NeDbClient = require('./clients/nedbclient');
4const MongoClient = require('./clients/mongoclient');
5
6/**
7 * Connect to current database
8 *
9 * @param {String} url
10 * @param {Object} options
11 * @returns {Promise}
12 */
13exports.connect = function(url, options) {
14 if (url.indexOf('nedb://') > -1) {
15 // url example: nedb://path/to/file/folder
16 return NeDbClient.connect(url, options).then(function(db) {
17 global.CLIENT = db;
18 return db;
19 });
20 } else if(url.indexOf('mongodb://') > -1) {
21 // url example: 'mongodb://localhost:27017/myproject'
22 return MongoClient.connect(url, options).then(function(db) {
23 global.CLIENT = db;
24 return db;
25 });
26 } else {
27 return Promise.reject(new Error('Unrecognized DB connection url.'));
28 }
29};
\No newline at end of file