1 | var cradle = require('cradle'),
|
2 | logger = require('./logger'),
|
3 | db;
|
4 |
|
5 | module.exports.create_connection = function (options) {
|
6 | if (typeof(options) === 'string') {
|
7 | logger.info("Connecting to %s",options);
|
8 | db = new (cradle.Connection)().database(options);
|
9 |
|
10 | return db;
|
11 | }
|
12 |
|
13 | var _options = {},
|
14 | db_name = options.db,
|
15 | url = options.url,
|
16 | port = options.port;
|
17 |
|
18 | _options.secure = options.secure || false;
|
19 | _options.auth = options.auth;
|
20 | _options.cache = options.cache || false;
|
21 |
|
22 | db = new (cradle.Connection)(url,port, _options).database(db_name);
|
23 |
|
24 | return db;
|
25 | };
|
26 |
|
27 |
|
28 | module.exports.connection = function () {
|
29 |
|
30 | return db;
|
31 | };
|
32 |
|
33 |
|