File tree Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,11 @@ const Promise = require('bluebird');
7
7
const fs = require ( 'fs' ) ;
8
8
const Logger = require ( 'mongodb' ) . Logger ;
9
9
10
- const singletons = require ( '../util/singletons' ) ;
11
- const SINGLETON_NAME = 'appmixer-lib.db.db.client' ;
10
+ let db = null ;
12
11
13
12
module . exports . db = function ( ) {
14
13
15
- const db = singletons . get ( SINGLETON_NAME ) ;
16
- if ( ! db ) {
14
+ if ( db === null ) {
17
15
throw new Error ( 'Mongo DB not connected!' ) ;
18
16
}
19
17
return db ;
@@ -39,8 +37,7 @@ module.exports.connect = async function(connection) {
39
37
Logger . setLevel ( process . env . LOG_LEVEL . toLowerCase ( ) ) ;
40
38
}
41
39
42
- let db = singletons . get ( SINGLETON_NAME ) ;
43
- if ( db ) {
40
+ if ( db !== null ) {
44
41
return db ;
45
42
}
46
43
@@ -56,7 +53,8 @@ module.exports.connect = async function(connection) {
56
53
let uri = connection . uri || 'mongodb://' + connection . host + ':' + connection . port + '/' + connection . dbName ;
57
54
58
55
let options = {
59
- promiseLibrary : Promise
56
+ promiseLibrary : Promise ,
57
+ useNewUrlParser : true
60
58
} ;
61
59
62
60
// file to cert
@@ -74,6 +72,5 @@ module.exports.connect = async function(connection) {
74
72
75
73
const client = await MongoClient . connect ( uri , options ) ;
76
74
db = client . db ( connection . dbName ) ;
77
- singletons . set ( SINGLETON_NAME , db ) ;
78
75
return db ;
79
76
} ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
-
3
2
const Promise = require ( 'bluebird' ) ;
4
3
const redis = Promise . promisifyAll ( require ( 'redis' ) ) ;
5
4
const check = require ( 'check-types' ) ;
6
5
const fs = require ( 'fs' ) ;
7
6
8
- const SINGLETON_NAME = 'appmixer-lib.db.redis.client' ;
9
- const singletons = require ( '../util/singletons' ) ;
7
+ let client = null ;
10
8
11
9
module . exports . client = function ( ) {
12
10
13
- const client = singletons . get ( SINGLETON_NAME ) ;
14
- if ( ! client ) {
11
+ if ( client === null ) {
15
12
throw new Error ( 'Redis DB not connected!' ) ;
16
13
}
17
14
return client ;
@@ -27,8 +24,7 @@ module.exports.client = function() {
27
24
*/
28
25
module . exports . connect = async function ( connection ) {
29
26
30
- let client = singletons . get ( SINGLETON_NAME ) ;
31
- if ( client ) {
27
+ if ( client !== null ) {
32
28
return client ;
33
29
}
34
30
@@ -46,6 +42,5 @@ module.exports.connect = async function(connection) {
46
42
}
47
43
48
44
client = connection . uri ? redis . createClient ( connection . uri , options ) : redis . createClient ( ) ;
49
- singletons . set ( SINGLETON_NAME , client ) ;
50
45
return client ;
51
46
} ;
You can’t perform that action at this time.
0 commit comments