From 6415450634642b01a92d9c8fd8a00a28cb3233e2 Mon Sep 17 00:00:00 2001 From: brianc Date: Thu, 7 Mar 2013 09:47:04 -0600 Subject: [PATCH] deprecate pauseDrain/resumeDrain & auto-releasing client pool --- lib/client.js | 12 ++++++++++++ lib/deprecate.js | 25 +++++++++++++++++++++++++ lib/pool.js | 9 +++++++++ package.json | 41 ++++++++++++++++++++++++++--------------- 4 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 lib/deprecate.js diff --git a/lib/client.js b/lib/client.js index bd03425..cc9e2b8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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'); } diff --git a/lib/deprecate.js b/lib/deprecate.js new file mode 100644 index 0000000..c587623 --- /dev/null +++ b/lib/deprecate.js @@ -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); +}; diff --git a/lib/pool.js b/lib/pool.js index 15cf77e..ce31473 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -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); diff --git a/package.json b/package.json index bb347f1..cd6d8f5 100644 --- a/package.json +++ b/package.json @@ -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 ", - "main" : "./lib", - "dependencies" : { - "generic-pool" : "2.0.2" + "author": "Brian Carlson ", + "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" + } }