pg 6.1.2 → 6.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/client.js +2 -1
- package/lib/connection.js +18 -2
- package/lib/defaults.js +7 -1
- package/lib/query.js +15 -3
- package/lib/result.js +8 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ var config = {
|
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
//this initializes a connection pool
|
|
75
|
-
//it will keep idle connections open for
|
|
75
|
+
//it will keep idle connections open for 30 seconds
|
|
76
76
|
//and set a limit of maximum 10 idle clients
|
|
77
77
|
var pool = new pg.Pool(config);
|
|
78
78
|
|
|
@@ -83,8 +83,8 @@ pool.connect(function(err, client, done) {
|
|
|
83
83
|
return console.error('error fetching client from pool', err);
|
|
84
84
|
}
|
|
85
85
|
client.query('SELECT $1::int AS number', ['1'], function(err, result) {
|
|
86
|
-
//call `done()` to release the client back to the pool
|
|
87
|
-
done();
|
|
86
|
+
//call `done(err)` to release the client back to the pool (or destroy it if there is an error)
|
|
87
|
+
done(err);
|
|
88
88
|
|
|
89
89
|
if(err) {
|
|
90
90
|
return console.error('error running query', err);
|
package/lib/client.js
CHANGED
|
@@ -169,7 +169,7 @@ Client.prototype.connect = function(callback) {
|
|
|
169
169
|
self.readyForQuery = true;
|
|
170
170
|
self._pulseQueryQueue();
|
|
171
171
|
if(activeQuery) {
|
|
172
|
-
activeQuery.handleReadyForQuery();
|
|
172
|
+
activeQuery.handleReadyForQuery(con);
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
175
|
|
|
@@ -182,6 +182,7 @@ Client.prototype.connect = function(callback) {
|
|
|
182
182
|
if(!callback) {
|
|
183
183
|
return self.emit('error', error);
|
|
184
184
|
}
|
|
185
|
+
con.end(); // make sure ECONNRESET errors don't cause error events
|
|
185
186
|
callback(error);
|
|
186
187
|
callback = null;
|
|
187
188
|
});
|
package/lib/connection.js
CHANGED
|
@@ -13,6 +13,21 @@ var util = require('util');
|
|
|
13
13
|
var Writer = require('buffer-writer');
|
|
14
14
|
var Reader = require('packet-reader');
|
|
15
15
|
|
|
16
|
+
var indexOf =
|
|
17
|
+
'indexOf' in Buffer.prototype ?
|
|
18
|
+
function indexOf(buffer, value, start) {
|
|
19
|
+
return buffer.indexOf(value, start);
|
|
20
|
+
} :
|
|
21
|
+
function indexOf(buffer, value, start) {
|
|
22
|
+
for (var i = start, len = buffer.length; i < len; i++) {
|
|
23
|
+
if (buffer[i] === value) {
|
|
24
|
+
return i;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return -1;
|
|
29
|
+
};
|
|
30
|
+
|
|
16
31
|
var TEXT_MODE = 0;
|
|
17
32
|
var BINARY_MODE = 1;
|
|
18
33
|
var Connection = function(config) {
|
|
@@ -647,8 +662,9 @@ Connection.prototype.readBytes = function(buffer, length) {
|
|
|
647
662
|
|
|
648
663
|
Connection.prototype.parseCString = function(buffer) {
|
|
649
664
|
var start = this.offset;
|
|
650
|
-
|
|
651
|
-
|
|
665
|
+
var end = indexOf(buffer, 0, start);
|
|
666
|
+
this.offset = end + 1;
|
|
667
|
+
return buffer.toString(this.encoding, start, end);
|
|
652
668
|
};
|
|
653
669
|
//end parsing methods
|
|
654
670
|
module.exports = Connection;
|
package/lib/defaults.js
CHANGED
|
@@ -62,7 +62,13 @@ var defaults = module.exports = {
|
|
|
62
62
|
parseInputDatesAsUTC: false
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
var pgTypes = require('pg-types');
|
|
66
|
+
// save default parsers
|
|
67
|
+
var parseBigInteger = pgTypes.getTypeParser(20, 'text');
|
|
68
|
+
var parseBigIntegerArray = pgTypes.getTypeParser(1016, 'text');
|
|
69
|
+
|
|
65
70
|
//parse int8 so you can get your count values as actual numbers
|
|
66
71
|
module.exports.__defineSetter__("parseInt8", function(val) {
|
|
67
|
-
|
|
72
|
+
pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger);
|
|
73
|
+
pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray);
|
|
68
74
|
});
|
package/lib/query.js
CHANGED
|
@@ -80,7 +80,19 @@ Query.prototype.handleRowDescription = function(msg) {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
Query.prototype.handleDataRow = function(msg) {
|
|
83
|
-
var row
|
|
83
|
+
var row;
|
|
84
|
+
|
|
85
|
+
if (this._canceledDueToError) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
row = this._result.parseRow(msg.fields);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
this._canceledDueToError = err;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
84
96
|
this.emit('row', row, this._result);
|
|
85
97
|
if (this._accumulateRows) {
|
|
86
98
|
this._result.addRow(row);
|
|
@@ -104,9 +116,9 @@ Query.prototype.handleEmptyQuery = function(con) {
|
|
|
104
116
|
}
|
|
105
117
|
};
|
|
106
118
|
|
|
107
|
-
Query.prototype.handleReadyForQuery = function() {
|
|
119
|
+
Query.prototype.handleReadyForQuery = function(con) {
|
|
108
120
|
if(this._canceledDueToError) {
|
|
109
|
-
return this.handleError(this._canceledDueToError);
|
|
121
|
+
return this.handleError(this._canceledDueToError, con);
|
|
110
122
|
}
|
|
111
123
|
if(this.callback) {
|
|
112
124
|
this.callback(null, this._result);
|
package/lib/result.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
var types = require('pg-types');
|
|
10
|
+
var escape = require('js-string-escape');
|
|
10
11
|
|
|
11
12
|
//result object returned from query
|
|
12
13
|
//in the 'end' event and also
|
|
@@ -75,13 +76,13 @@ Result.prototype.addRow = function(row) {
|
|
|
75
76
|
|
|
76
77
|
var inlineParser = function(fieldName, i) {
|
|
77
78
|
return "\nthis['" +
|
|
78
|
-
//fields containing single quotes will break
|
|
79
|
-
//the evaluated javascript unless they are escaped
|
|
80
|
-
//see https://github.com/brianc/node-postgres/issues/507
|
|
81
|
-
//Addendum: However, we need to make sure to replace all
|
|
82
|
-
//occurences of apostrophes, not just the first one.
|
|
83
|
-
//See https://github.com/brianc/node-postgres/issues/934
|
|
84
|
-
fieldName
|
|
79
|
+
// fields containing single quotes will break
|
|
80
|
+
// the evaluated javascript unless they are escaped
|
|
81
|
+
// see https://github.com/brianc/node-postgres/issues/507
|
|
82
|
+
// Addendum: However, we need to make sure to replace all
|
|
83
|
+
// occurences of apostrophes, not just the first one.
|
|
84
|
+
// See https://github.com/brianc/node-postgres/issues/934
|
|
85
|
+
escape(fieldName) +
|
|
85
86
|
"'] = " +
|
|
86
87
|
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
|
|
87
88
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.6",
|
|
4
4
|
"description": "PostgreSQL client - pure javascript & libpq with the same API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postgres",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"main": "./lib",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"buffer-writer": "1.0.1",
|
|
22
|
+
"js-string-escape": "1.0.1",
|
|
22
23
|
"packet-reader": "0.2.0",
|
|
23
24
|
"pg-connection-string": "0.1.3",
|
|
24
25
|
"pg-pool": "1.*",
|