dsi-icl/optimise

View on GitHub
packages/optimise-sync/src/utils/db-connection.js

Summary

Maintainability
A
3 hrs
Test Coverage
import { MongoClient } from 'mongodb';

let connection;

export default () => new Promise((resolve, reject) => {
    if (connection === undefined) {
        MongoClient.connect(global.config.mongo).then(client => {
            connection = client;
            resolve(connection);
        }).catch(err => {
            if (err !== null)
                reject(err);
        });
    } else
        resolve(connection);
});