pg-promise
Advanced tools
Comparing version 10.8.7 to 10.9.0
@@ -24,2 +24,20 @@ /* | ||
/** | ||
* Global instance of the database pool repository. | ||
* | ||
* @return {{dbMap: {}, dbs: []}} | ||
*/ | ||
static get instance() { | ||
const s = Symbol.for(`pgPromise`); | ||
let scope = global[s]; | ||
if (!scope) { | ||
scope = { | ||
dbMap: {}, // map of used database context keys (connection + dc) | ||
dbs: [] // all database objects | ||
}; | ||
global[s] = scope; | ||
} | ||
return scope; | ||
} | ||
/** | ||
* @method DatabasePool.register | ||
@@ -37,4 +55,5 @@ * @static | ||
npm.utils.addReadProp(db, `$cnKey`, cnKey, true); | ||
if (cnKey in DatabasePool.dbMap) { | ||
DatabasePool.dbMap[cnKey]++; | ||
const {dbMap, dbs} = DatabasePool.instance; | ||
if (cnKey in dbMap) { | ||
dbMap[cnKey]++; | ||
/* istanbul ignore if */ | ||
@@ -45,5 +64,5 @@ if (!db.$config.options.noWarnings) { | ||
} else { | ||
DatabasePool.dbMap[cnKey] = 1; | ||
dbMap[cnKey] = 1; | ||
} | ||
DatabasePool.dbs.push(db); | ||
dbs.push(db); | ||
} | ||
@@ -58,4 +77,5 @@ | ||
const cnKey = db.$cnKey; | ||
if (!--DatabasePool.dbMap[cnKey]) { | ||
delete DatabasePool.dbMap[cnKey]; | ||
const {dbMap} = DatabasePool.instance; | ||
if (!--dbMap[cnKey]) { | ||
delete dbMap[cnKey]; | ||
} | ||
@@ -69,7 +89,8 @@ } | ||
static shutDown() { | ||
DatabasePool.dbs.forEach(db => { | ||
const {instance} = DatabasePool; | ||
instance.dbs.forEach(db => { | ||
db.$destroy(); | ||
}); | ||
DatabasePool.dbs.length = 0; | ||
DatabasePool.dbMap = {}; | ||
instance.dbs.length = 0; | ||
instance.dbMap = {}; | ||
} | ||
@@ -99,7 +120,2 @@ | ||
///////////////////// | ||
// Static Properties: | ||
DatabasePool.dbMap = {}; // map of used database context keys (connection + dc) | ||
DatabasePool.dbs = []; // all database objects | ||
module.exports = {DatabasePool}; |
{ | ||
"name": "pg-promise", | ||
"version": "10.8.7", | ||
"version": "10.9.0", | ||
"description": "PostgreSQL interface for Node.js", | ||
@@ -49,6 +49,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/node": "14.14.20", | ||
"@types/node": "14.14.21", | ||
"bluebird": "3.7.2", | ||
"coveralls": "3.1.0", | ||
"eslint": "7.17.0", | ||
"eslint": "7.18.0", | ||
"istanbul": "0.4.5", | ||
@@ -55,0 +55,0 @@ "jasmine-node": "3.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
420629
9684
2