Skip to content

Commit 6415450

Browse files
committed
deprecate pauseDrain/resumeDrain & auto-releasing client pool
1 parent 6879453 commit 6415450

File tree

4 files changed

+72
-15
lines changed

4 files changed

+72
-15
lines changed

lib/client.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var Connection = require(__dirname + '/connection');
1010
var CopyFromStream = require(__dirname + '/copystream').CopyFromStream;
1111
var CopyToStream = require(__dirname + '/copystream').CopyToStream;
1212

13+
var deprecate = require('deprecate');
14+
1315
var Client = function(config) {
1416
EventEmitter.call(this);
1517

@@ -256,11 +258,21 @@ Client.prototype.query = function(config, values, callback) {
256258
//prevents client from otherwise emitting 'drain' event until 'resumeDrain' is
257259
//called
258260
Client.prototype.pauseDrain = function() {
261+
deprecate('Client.prototype.pauseDrain is deprecated and will be removed it v1.0.0 (very soon)',
262+
'please see the following for more details:',
263+
'https://github.com/brianc/node-postgres/wiki/pg',
264+
'https://github.com/brianc/node-postgres/issues/227',
265+
'https://github.com/brianc/node-postgres/pull/274');
259266
this._drainPaused = 1;
260267
};
261268

262269
//resume raising 'drain' event
263270
Client.prototype.resumeDrain = function() {
271+
deprecate('Client.prototype.resumeDrain is deprecated and will be removed it v1.0.0 (very soon)',
272+
'please see the following for more details:',
273+
'https://github.com/brianc/node-postgres/wiki/pg',
274+
'https://github.com/brianc/node-postgres/issues/227',
275+
'https://github.com/brianc/node-postgres/pull/274');
264276
if(this._drainPaused > 1) {
265277
this.emit('drain');
266278
}

lib/deprecate.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var os = require('os');
2+
var defaults = require(__dirname + '/defaults');
3+
4+
var hits = {
5+
};
6+
var deprecate = module.exports = function(methodName, message) {
7+
if(defaults.hideDeprecationWarnings) return;
8+
if(hits[deprecate.caller]) return;
9+
hits[deprecate.caller] = true;
10+
process.stderr.write(os.EOL);
11+
process.stderr.write('\x1b[31;1m');
12+
process.stderr.write('WARNING!!');
13+
process.stderr.write(os.EOL);
14+
process.stderr.write(methodName);
15+
process.stderr.write(os.EOL);
16+
for(var i = 1; i < arguments.length; i++) {
17+
process.stderr.write(arguments[i]);
18+
process.stderr.write(os.EOL);
19+
}
20+
process.stderr.write('\x1b[0m');
21+
process.stderr.write(os.EOL);
22+
process.stderr.write("You can silence these warnings with `require('pg').defaults.hideDeprecationWarnings = true`");
23+
process.stderr.write(os.EOL);
24+
process.stderr.write(os.EOL);
25+
};

lib/pool.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var EventEmitter = require('events').EventEmitter;
33
var defaults = require(__dirname + '/defaults');
44
var genericPool = require('generic-pool');
55

6+
var deprecate = require('deprecate');
7+
68
var pools = {
79
//dictionary of all key:pool pairs
810
all: {},
@@ -77,6 +79,13 @@ var errorMessage = [
7779
].join(require('os').EOL);
7880

7981
var oldConnect = function(pool, client, cb) {
82+
deprecate('pg.connect(function(err, client) { ...}) is deprecated and will be removed it v1.0.0 (very soon)',
83+
'instead, use pg.connect(function(err, client, done) { ... })',
84+
'automatic releasing of clients back to the pool was a mistake and will be removed',
85+
'please see the following for more details:',
86+
'https://github.com/brianc/node-postgres/wiki/pg',
87+
'https://github.com/brianc/node-postgres/issues/227',
88+
'https://github.com/brianc/node-postgres/pull/274');
8089
var tid = setTimeout(function() {
8190
console.error(errorMessage);
8291
}, alarmDuration);

package.json

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
{ "name": "pg",
1+
{
2+
"name": "pg",
23
"version": "0.13.3",
34
"description": "PostgreSQL client - pure javascript & libpq with the same API",
4-
"keywords" : ["postgres", "pg", "libpq", "postgre", "database", "rdbms"],
5+
"keywords": [
6+
"postgres",
7+
"pg",
8+
"libpq",
9+
"postgre",
10+
"database",
11+
"rdbms"
12+
],
513
"homepage": "http://github.com/brianc/node-postgres",
6-
"repository" : {
7-
"type" : "git",
8-
"url" : "git://github.com/brianc/node-postgres.git"
14+
"repository": {
15+
"type": "git",
16+
"url": "git://github.com/brianc/node-postgres.git"
917
},
10-
"author" : "Brian Carlson <[email protected]>",
11-
"main" : "./lib",
12-
"dependencies" : {
13-
"generic-pool" : "2.0.2"
18+
"author": "Brian Carlson <[email protected]>",
19+
"main": "./lib",
20+
"dependencies": {
21+
"generic-pool": "2.0.2",
22+
"deprecate": "~0.1.0"
1423
},
15-
"devDependencies" : {
16-
"jshint" : "git://github.com/jshint/jshint.git"
24+
"devDependencies": {
25+
"jshint": "git://github.com/jshint/jshint.git"
1726
},
18-
"scripts" : {
19-
"test" : "make test-all connectionString=pg://postgres@localhost:5432/postgres",
27+
"scripts": {
28+
"test": "make test-all connectionString=pg://postgres@localhost:5432/postgres",
2029
"prepublish": "rm -r build || (exit 0)",
21-
"install" : "node-gyp rebuild || (exit 0)"
30+
"install": "node-gyp rebuild || (exit 0)"
2231
},
23-
"engines" : { "node": ">= 0.8.0" }
32+
"engines": {
33+
"node": ">= 0.8.0"
34+
}
2435
}

0 commit comments

Comments
 (0)