deprecate pauseDrain/resumeDrain & auto-releasing client pool

This commit is contained in:
brianc 2013-03-07 09:47:04 -06:00
parent 6879453d83
commit 6415450634
4 changed files with 72 additions and 15 deletions

View File

@ -10,6 +10,8 @@ var Connection = require(__dirname + '/connection');
var CopyFromStream = require(__dirname + '/copystream').CopyFromStream;
var CopyToStream = require(__dirname + '/copystream').CopyToStream;
var deprecate = require('deprecate');
var Client = function(config) {
EventEmitter.call(this);
@ -256,11 +258,21 @@ Client.prototype.query = function(config, values, callback) {
//prevents client from otherwise emitting 'drain' event until 'resumeDrain' is
//called
Client.prototype.pauseDrain = function() {
deprecate('Client.prototype.pauseDrain is deprecated and will be removed it v1.0.0 (very soon)',
'please see the following for more details:',
'https://github.com/brianc/node-postgres/wiki/pg',
'https://github.com/brianc/node-postgres/issues/227',
'https://github.com/brianc/node-postgres/pull/274');
this._drainPaused = 1;
};
//resume raising 'drain' event
Client.prototype.resumeDrain = function() {
deprecate('Client.prototype.resumeDrain is deprecated and will be removed it v1.0.0 (very soon)',
'please see the following for more details:',
'https://github.com/brianc/node-postgres/wiki/pg',
'https://github.com/brianc/node-postgres/issues/227',
'https://github.com/brianc/node-postgres/pull/274');
if(this._drainPaused > 1) {
this.emit('drain');
}

25
lib/deprecate.js Normal file
View File

@ -0,0 +1,25 @@
var os = require('os');
var defaults = require(__dirname + '/defaults');
var hits = {
};
var deprecate = module.exports = function(methodName, message) {
if(defaults.hideDeprecationWarnings) return;
if(hits[deprecate.caller]) return;
hits[deprecate.caller] = true;
process.stderr.write(os.EOL);
process.stderr.write('\x1b[31;1m');
process.stderr.write('WARNING!!');
process.stderr.write(os.EOL);
process.stderr.write(methodName);
process.stderr.write(os.EOL);
for(var i = 1; i < arguments.length; i++) {
process.stderr.write(arguments[i]);
process.stderr.write(os.EOL);
}
process.stderr.write('\x1b[0m');
process.stderr.write(os.EOL);
process.stderr.write("You can silence these warnings with `require('pg').defaults.hideDeprecationWarnings = true`");
process.stderr.write(os.EOL);
process.stderr.write(os.EOL);
};

View File

@ -3,6 +3,8 @@ var EventEmitter = require('events').EventEmitter;
var defaults = require(__dirname + '/defaults');
var genericPool = require('generic-pool');
var deprecate = require('deprecate');
var pools = {
//dictionary of all key:pool pairs
all: {},
@ -77,6 +79,13 @@ var errorMessage = [
].join(require('os').EOL);
var oldConnect = function(pool, client, cb) {
deprecate('pg.connect(function(err, client) { ...}) is deprecated and will be removed it v1.0.0 (very soon)',
'instead, use pg.connect(function(err, client, done) { ... })',
'automatic releasing of clients back to the pool was a mistake and will be removed',
'please see the following for more details:',
'https://github.com/brianc/node-postgres/wiki/pg',
'https://github.com/brianc/node-postgres/issues/227',
'https://github.com/brianc/node-postgres/pull/274');
var tid = setTimeout(function() {
console.error(errorMessage);
}, alarmDuration);

View File

@ -1,24 +1,35 @@
{ "name": "pg",
{
"name": "pg",
"version": "0.13.3",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords" : ["postgres", "pg", "libpq", "postgre", "database", "rdbms"],
"keywords": [
"postgres",
"pg",
"libpq",
"postgre",
"database",
"rdbms"
],
"homepage": "http://github.com/brianc/node-postgres",
"repository" : {
"type" : "git",
"url" : "git://github.com/brianc/node-postgres.git"
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git"
},
"author" : "Brian Carlson <brian.m.carlson@gmail.com>",
"main" : "./lib",
"dependencies" : {
"generic-pool" : "2.0.2"
"author": "Brian Carlson <brian.m.carlson@gmail.com>",
"main": "./lib",
"dependencies": {
"generic-pool": "2.0.2",
"deprecate": "~0.1.0"
},
"devDependencies" : {
"jshint" : "git://github.com/jshint/jshint.git"
"devDependencies": {
"jshint": "git://github.com/jshint/jshint.git"
},
"scripts" : {
"test" : "make test-all connectionString=pg://postgres@localhost:5432/postgres",
"scripts": {
"test": "make test-all connectionString=pg://postgres@localhost:5432/postgres",
"prepublish": "rm -r build || (exit 0)",
"install" : "node-gyp rebuild || (exit 0)"
"install": "node-gyp rebuild || (exit 0)"
},
"engines" : { "node": ">= 0.8.0" }
"engines": {
"node": ">= 0.8.0"
}
}