Split mongodb connection creation from DatabaseController.

This commit is contained in:
Nikita Lutsenko
2016-02-27 02:23:57 -08:00
parent d78c2746e9
commit 997da898eb
4 changed files with 54 additions and 23 deletions

View File

@@ -0,0 +1,29 @@
let mongodb = require('mongodb');
let MongoClient = mongodb.MongoClient;
export class MongoStorageAdapter {
// Private
_uri: string;
// Public
connectionPromise;
database;
constructor(uri: string) {
this._uri = uri;
}
connect() {
if (this.connectionPromise) {
return this.connectionPromise;
}
this.connectionPromise = MongoClient.connect(this._uri).then(database => {
this.database = database;
});
return this.connectionPromise;
}
}
export default MongoStorageAdapter;
module.exports = MongoStorageAdapter; // Required for tests