@glennjones/prompt
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "@glennjones/prompt", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -15,5 +15,6 @@ const { MongoClient, Db } = require('mongodb'); | ||
* @param {string} collectionName - The name of the collection to store the cache in | ||
* @param {Db=} db - The database object to use, instead of creating a new one with the uri and dbName | ||
* @constructor | ||
* */ | ||
constructor(uri, dbName, collectionName = 'cache') { | ||
constructor(uri, dbName, collectionName = 'cache', db) { | ||
super(); | ||
@@ -23,3 +24,3 @@ this.uri = uri; | ||
this.collectionName = collectionName; | ||
this.db = null; | ||
this.db = db; | ||
@@ -32,10 +33,12 @@ // Connect to the database | ||
// Connect to the database | ||
await MongoClient.connect(this.uri) | ||
.then((client) => { | ||
this.db = client.db(this.dbName); | ||
return; | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
if(this.db === undefined) { | ||
await MongoClient.connect(this.uri) | ||
.then((client) => { | ||
this.db = client.db(this.dbName); | ||
return; | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
} | ||
} | ||
@@ -42,0 +45,0 @@ |
87972
1549