Skip to content

Commit adca892

Browse files
Merge pull request #40 from martin-krcmar/remove-singleton
Singletons removed, not needed anymore
2 parents 04723af + edb778a commit adca892

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

db/db.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ const Promise = require('bluebird');
77
const fs = require('fs');
88
const Logger = require('mongodb').Logger;
99

10-
const singletons = require('../util/singletons');
11-
const SINGLETON_NAME = 'appmixer-lib.db.db.client';
10+
let db = null;
1211

1312
module.exports.db = function() {
1413

15-
const db = singletons.get(SINGLETON_NAME);
16-
if (!db) {
14+
if (db === null) {
1715
throw new Error('Mongo DB not connected!');
1816
}
1917
return db;
@@ -39,8 +37,7 @@ module.exports.connect = async function(connection) {
3937
Logger.setLevel(process.env.LOG_LEVEL.toLowerCase());
4038
}
4139

42-
let db = singletons.get(SINGLETON_NAME);
43-
if (db) {
40+
if (db !== null) {
4441
return db;
4542
}
4643

@@ -56,7 +53,8 @@ module.exports.connect = async function(connection) {
5653
let uri = connection.uri || 'mongodb://' + connection.host + ':' + connection.port + '/' + connection.dbName;
5754

5855
let options = {
59-
promiseLibrary: Promise
56+
promiseLibrary: Promise,
57+
useNewUrlParser: true
6058
};
6159

6260
// file to cert
@@ -74,6 +72,5 @@ module.exports.connect = async function(connection) {
7472

7573
const client = await MongoClient.connect(uri, options);
7674
db = client.db(connection.dbName);
77-
singletons.set(SINGLETON_NAME, db);
7875
return db;
7976
};

db/redis.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
'use strict';
2-
32
const Promise = require('bluebird');
43
const redis = Promise.promisifyAll(require('redis'));
54
const check = require('check-types');
65
const fs = require('fs');
76

8-
const SINGLETON_NAME = 'appmixer-lib.db.redis.client';
9-
const singletons = require('../util/singletons');
7+
let client = null;
108

119
module.exports.client = function() {
1210

13-
const client = singletons.get(SINGLETON_NAME);
14-
if (!client) {
11+
if (client === null) {
1512
throw new Error('Redis DB not connected!');
1613
}
1714
return client;
@@ -27,8 +24,7 @@ module.exports.client = function() {
2724
*/
2825
module.exports.connect = async function(connection) {
2926

30-
let client = singletons.get(SINGLETON_NAME);
31-
if (client) {
27+
if (client !== null) {
3228
return client;
3329
}
3430

@@ -46,6 +42,5 @@ module.exports.connect = async function(connection) {
4642
}
4743

4844
client = connection.uri ? redis.createClient(connection.uri, options) : redis.createClient();
49-
singletons.set(SINGLETON_NAME, client);
5045
return client;
5146
};

0 commit comments

Comments
 (0)