Skip to content

Commit

Permalink
preparing the release.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jun 25, 2017
1 parent 1a56018 commit 4b1954d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ test/typescript/*.js
test/typescript/*.map
typings/
generated.js
package-lock.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Release History

* 6.1.0 Switching over to the latest 6.4.0 `node-postgres` driver and its new connection pool. Released: June 25, 2017.
* 5.9.0 Added support SQL aliases, plus method `ColumnSet.assign`. Released: June 05, 2017.
* 5.8.0 Added support for warnings to class [QueryFile]. Released: May 29, 2017.
* 5.7.0 Major query formatting overhaul for passing in the calling context. Released: May 15, 2017
Expand Down
76 changes: 76 additions & 0 deletions lib/dbPool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

const npm = {
con: require('manakin').local,
utils: require('./utils')
};

/**
* @class DatabasePool
* @private
*/
class DatabasePool {

constructor() {
this.dbMap = {}; // map of used databases
this.dbs = []; // all database objects
}

/**
* @method DatabasePool.register
* @private
* @description
* - Registers each database object, to make sure no duplicates connections are used,
* and if they are, produce a warning;
* - Registers each Pool object, to be able to release them all when requested.
*
* @param {Database} db - The new Database object being registered.
*/
register(db) {
const cnKey = DatabasePool.normalizeConnection(db.$cn);
if (cnKey in this.dbMap) {
if (!db.$config.options.noWarnings) {
npm.con.warn('WARNING: Creating a duplicate database object for the same connection.\n%s\n',
npm.utils.getLocalStack(5));
}
} else {
this.dbMap[cnKey] = true;
}
this.dbs.push(db);
}

/**
* @method DatabasePool.shutDown
* @private
*/
shutDown() {
this.dbs.forEach(db => {
db.$destroy();
});
this.dbs.length = 0;
this.dbMap = {};
}

/**
* @method DatabasePool.normalizeConnection
* @static
* @private
* @description
* For connections that are objects it reorders the keys alphabetically,
* and then serializes the result into a JSON string.
*
* @param {string|object} cn - connection string or object
*/
static normalizeConnection(cn) {
if (typeof cn === 'object') {
const obj = {}, keys = Object.keys(cn).sort();
keys.forEach(name => {
obj[name] = cn[name];
});
cn = obj;
}
return JSON.stringify(cn);
}
}

module.exports = new DatabasePool();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-promise",
"version": "6.0.26",
"version": "6.1.0",
"description": "Promises interface for PostgreSQL",
"main": "lib/index.js",
"typings": "typescript/pg-promise.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion typescript/pg-promise.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////////////////////////////////////////
// Requires pg-promise v6.0.26 or later.
// Requires pg-promise v6.1.0 or later.
////////////////////////////////////////

import * as XPromise from './ext-promise'; // External Promise Provider
Expand Down

0 comments on commit 4b1954d

Please sign in to comment.