Skip to content

Commit 3d7c31f

Browse files
committed
Merge branch 'master' into benchmark
2 parents a28f156 + f98bbed commit 3d7c31f

35 files changed

+300
-732
lines changed

NEWS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
### v1.0 - not released yet
1+
All major and minor releases are briefly explained below.
2+
3+
For richer information consult the commit log on github with referenced pull requests.
4+
5+
We do not include break-fix version release in this file.
6+
7+
### v1.0
28

39
- remove deprecated functionality
410
- `pg.connect` now __requires__ 3 arguments
511
- Client#pauseDrain() / Client#resumeDrain removed
612
- numeric, decimal, and float data types no longer parsed into float before being returned. Will be returned from query results as `String`
713

14+
### v0.15.0
15+
16+
- client now emits `end` when disconnected from back-end server
17+
- if client is disconnected in the middle of a query, query receives an error
818

919
### v0.14.0
1020

lib/client.js

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ 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-
1513
var Client = function(config) {
1614
EventEmitter.call(this);
1715

@@ -171,6 +169,15 @@ Client.prototype.connect = function(callback) {
171169
}
172170
});
173171

172+
con.once('end', function() {
173+
if(self.activeQuery) {
174+
self.activeQuery.handleError(new Error('Stream unexpectedly ended during query execution'));
175+
self.activeQuery = null;
176+
}
177+
self.emit('end');
178+
});
179+
180+
174181
con.on('notice', function(msg) {
175182
self.emit('notice', msg);
176183
});
@@ -205,13 +212,7 @@ Client.prototype._pulseQueryQueue = function() {
205212
this.activeQuery.submit(this.connection);
206213
} else if(this.hasExecuted) {
207214
this.activeQuery = null;
208-
//TODO remove pauseDrain for v1.0
209-
if(this._drainPaused > 0) {
210-
this._drainPaused++;
211-
}
212-
else {
213-
this.emit('drain');
214-
}
215+
this.emit('drain');
215216
}
216217
}
217218
};
@@ -255,32 +256,6 @@ Client.prototype.query = function(config, values, callback) {
255256
return query;
256257
};
257258

258-
//prevents client from otherwise emitting 'drain' event until 'resumeDrain' is
259-
//called
260-
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',
266-
'feel free to get in touch via github if you have questions');
267-
this._drainPaused = 1;
268-
};
269-
270-
//resume raising 'drain' event
271-
Client.prototype.resumeDrain = function() {
272-
deprecate('Client.prototype.resumeDrain is deprecated and will be removed it v1.0.0 (very soon)',
273-
'please see the following for more details:',
274-
'https://github.com/brianc/node-postgres/wiki/pg',
275-
'https://github.com/brianc/node-postgres/issues/227',
276-
'https://github.com/brianc/node-postgres/pull/274',
277-
'feel free to get in touch via github if you have questions');
278-
if(this._drainPaused > 1) {
279-
this.emit('drain');
280-
}
281-
this._drainPaused = 0;
282-
};
283-
284259
Client.prototype.end = function() {
285260
this.connection.end();
286261
};

lib/connection.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var EventEmitter = require('events').EventEmitter;
44
var util = require('util');
55

66
var utils = require(__dirname + '/utils');
7-
var Writer = require(__dirname + '/writer');
7+
var Writer = require('buffer-writer');
88

99
var Connection = function(config) {
1010
EventEmitter.call(this);
@@ -18,6 +18,7 @@ var Connection = function(config) {
1818
this.parsedStatements = {};
1919
this.writer = new Writer();
2020
this.ssl = config.ssl || false;
21+
this._ending = false;
2122
};
2223

2324
util.inherits(Connection, EventEmitter);
@@ -37,9 +38,18 @@ Connection.prototype.connect = function(port, host) {
3738
});
3839

3940
this.stream.on('error', function(error) {
41+
//don't raise ECONNRESET errors - they can & should be ignored
42+
//during disconnect
43+
if(self._ending && error.code == 'ECONNRESET') {
44+
return;
45+
}
4046
self.emit('error', error);
4147
});
4248

49+
this.stream.on('end', function() {
50+
self.emit('end');
51+
});
52+
4353
if(this.ssl) {
4454
this.stream.once('data', function(buffer) {
4555
self.setBuffer(buffer);
@@ -259,6 +269,7 @@ Connection.prototype.end = function() {
259269
//0x58 = 'X'
260270
this.writer.add(emptyBuffer);
261271
this._send(0x58);
272+
this._ending = true;
262273
};
263274

264275
Connection.prototype.describe = function(msg, more) {

lib/defaults.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,3 @@ module.exports = {
3333
//pool log function / boolean
3434
poolLog: false
3535
};
36-
37-
var deprecate = require('deprecate');
38-
//getter/setter to disable deprecation warnings
39-
module.exports.__defineGetter__("hideDeprecationWarnings", function() {
40-
return deprecate.silent;
41-
});
42-
module.exports.__defineSetter__("hideDeprecationWarnings", function(val) {
43-
deprecate.silence = val;
44-
});

lib/deprecate.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/native/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ var clientBuilder = function(config) {
198198
}
199199
});
200200

201+
connection.on('_end', function() {
202+
process.nextTick(function() {
203+
if(connection._activeQuery) {
204+
connection._activeQuery.handleError(new Error("Connection was ended during query"));
205+
}
206+
connection.emit('end');
207+
});
208+
});
209+
201210
connection.on('_readyForQuery', function() {
202211
var q = this._activeQuery;
203212
//a named query finished being prepared

lib/pool.js

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

6-
var deprecate = require('deprecate');
7-
86
var pools = {
97
//dictionary of all key:pool pairs
108
all: {},
@@ -54,64 +52,17 @@ var pools = {
5452
pool.connect = function(cb) {
5553
pool.acquire(function(err, client) {
5654
if(err) return cb(err, null, function() {/*NOOP*/});
57-
//support both 2 (old) and 3 arguments
58-
(cb.length > 2 ? newConnect : oldConnect)(pool, client, cb);
55+
cb(null, client, function(err) {
56+
if(err) {
57+
pool.destroy(client);
58+
} else {
59+
pool.release(client);
60+
}
61+
});
5962
});
6063
};
6164
return pool;
6265
}
6366
};
6467

65-
//the old connect method of the pool
66-
//would automatically subscribe to the 'drain'
67-
//event and automatically return the client to
68-
//the pool once 'drain' fired once. This caused
69-
//a bunch of problems, but for backwards compatibility
70-
//we're leaving it in
71-
var alarmDuration = 5000;
72-
var errorMessage = [
73-
'A client has been checked out from the pool for longer than ' + alarmDuration + ' ms.',
74-
'You might have a leak!',
75-
'You should use the following new way to check out clients','pg.connect(function(err, client, done)) {',
76-
' //do something',
77-
' done(); //call done() to signal you are finished with the client',
78-
'}'
79-
].join(require('os').EOL);
80-
81-
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',
89-
'feel free to get in touch via github if you have questions');
90-
var tid = setTimeout(function() {
91-
console.error(errorMessage);
92-
}, alarmDuration);
93-
var onError = function() {
94-
clearTimeout(tid);
95-
client.removeListener('drain', release);
96-
};
97-
var release = function() {
98-
clearTimeout(tid);
99-
pool.release(client);
100-
client.removeListener('error', onError);
101-
};
102-
client.once('drain', release);
103-
client.once('error', onError);
104-
cb(null, client);
105-
};
106-
107-
var newConnect = function(pool, client, cb) {
108-
cb(null, client, function(err) {
109-
if(err) {
110-
pool.destroy(client);
111-
} else {
112-
pool.release(client);
113-
}
114-
});
115-
};
116-
11768
module.exports = pools;

lib/types/binaryParsers.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var deprecate = require('deprecate');
2-
31
var parseBits = function(data, bits, offset, invert, callback) {
42
offset = offset || 0;
53
invert = invert || false;
@@ -47,12 +45,6 @@ var parseBits = function(data, bits, offset, invert, callback) {
4745
};
4846

4947
var parseFloatFromBits = function(data, precisionBits, exponentBits) {
50-
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
51-
'JavaScript has a hard time with floats and there is precision loss which can cause',
52-
'unexpected, hard to trace, potentially bad bugs in your program',
53-
'for more information see the following:',
54-
'https://github.com/brianc/node-postgres/pull/271',
55-
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
5648
var bias = Math.pow(2, exponentBits - 1) - 1;
5749
var sign = parseBits(data, 1);
5850
var exponent = parseBits(data, exponentBits, 1);

lib/types/textParsers.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var deprecate = require('deprecate');
2-
31
var arrayParser = require(__dirname + "/arrayParser.js");
42

53
//parses PostgreSQL server formatted date strings into javascript date objects
@@ -78,18 +76,8 @@ var parseIntegerArray = function(val) {
7876
};
7977

8078
var parseFloatArray = function(val) {
81-
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
82-
'JavaScript has a hard time with floats and there is precision loss which can cause',
83-
'unexpected, hard to trace, potentially bad bugs in your program',
84-
'for more information see the following:',
85-
'https://github.com/brianc/node-postgres/pull/271',
86-
'in node-postgres v1.0.0 all floats & decimals will be returned as strings',
87-
'feel free to get in touch via a github issue if you have any questions');
8879
if(!val) { return null; }
89-
var p = arrayParser.create(val, function(entry){
90-
if(entry !== null) {
91-
entry = parseFloat(entry, 10);
92-
}
80+
var p = arrayParser.create(val, function(entry) {
9381
return entry;
9482
});
9583

@@ -171,27 +159,11 @@ var parseInteger = function(val) {
171159
return parseInt(val, 10);
172160
};
173161

174-
var parseFloatAndWarn = function(val) {
175-
deprecate('parsing and returning floats from PostgreSQL server is deprecated',
176-
'JavaScript has a hard time with floats and there is precision loss which can cause',
177-
'unexpected, hard to trace, potentially bad bugs in your program',
178-
'for more information see the following:',
179-
'https://github.com/brianc/node-postgres/pull/271',
180-
'in node-postgres v1.0.0 all floats & decimals will be returned as strings');
181-
return parseFloat(val);
182-
};
183-
184162
var init = function(register) {
185163
register(20, parseInteger);
186164
register(21, parseInteger);
187165
register(23, parseInteger);
188166
register(26, parseInteger);
189-
//TODO remove for v1.0
190-
register(1700, parseFloatAndWarn);
191-
//TODO remove for v1.0
192-
register(700, parseFloatAndWarn);
193-
//TODO remove for v1.0
194-
register(701, parseFloatAndWarn);
195167
register(16, parseBool);
196168
register(1082, parseDate); // date
197169
register(1114, parseDate); // timestamp without timezone

0 commit comments

Comments
 (0)