MCPcopy Index your code
hub / github.com/deployd/deployd / getConnection

Function getConnection

lib/db.js:129–154  ·  view source on GitHub ↗
(db)

Source from the content-addressed store, hash-verified

127module.exports.Store = Store;
128
129function 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
156function collection(store, fn) {
157 var db = store._db;

Callers 2

db.jsFile · 0.85
collectionFunction · 0.85

Calls 3

errorFunction · 0.85
resolveFunction · 0.85
rejectFunction · 0.85

Tested by

no test coverage detected