(db)
| 127 | module.exports.Store = Store; |
| 128 | |
| 129 | function getConnection(db) { |
| 130 | if (db.Db) return Promise.resolve(db.Db); // reuse connection |
| 131 | if (typeof db.connectionString !== "string" || db.connectionString.length === 0) { |
| 132 | error(new Error("Cannot initialize store. A proper connection string was not specified.")); |
| 133 | process.exit(1); |
| 134 | } |
| 135 | return new Promise(function(resolve, reject) { |
| 136 | try { |
| 137 | mongodb.MongoClient.connect(db.connectionString, db.connectionOptions, function (err, database) { |
| 138 | if (!err) { |
| 139 | db.Db = database; |
| 140 | resolve(database); |
| 141 | } |
| 142 | else { |
| 143 | // log error |
| 144 | error(new Error("Cannot open store: " + err)); |
| 145 | // hide sensitive database connection error details |
| 146 | reject("Database connection error"); |
| 147 | } |
| 148 | }); |
| 149 | } catch(e){ |
| 150 | error(e); |
| 151 | reject("Database connection error"); |
| 152 | } |
| 153 | }); |
| 154 | } |
| 155 | |
| 156 | function collection(store, fn) { |
| 157 | var db = store._db; |
no test coverage detected