pg 8.2.2 → 8.4.0
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 +1 -1
- package/lib/client.js +474 -464
- package/lib/connection-parameters.js +104 -107
- package/lib/connection.js +168 -173
- package/lib/defaults.js +2 -7
- package/lib/index.js +0 -7
- package/lib/native/client.js +0 -12
- package/lib/native/query.js +0 -7
- package/lib/query.js +22 -40
- package/lib/result.js +76 -81
- package/lib/type-overrides.js +0 -7
- package/lib/utils.js +0 -7
- package/package.json +13 -7
package/lib/native/query.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* README.md file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
2
|
|
|
10
3
|
var EventEmitter = require('events').EventEmitter
|
|
11
4
|
var util = require('util')
|
package/lib/query.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* README.md file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
2
|
|
|
10
3
|
const { EventEmitter } = require('events')
|
|
11
4
|
|
|
@@ -176,30 +169,26 @@ class Query extends EventEmitter {
|
|
|
176
169
|
}
|
|
177
170
|
|
|
178
171
|
_getRows(connection, rows) {
|
|
179
|
-
connection.execute(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
true
|
|
185
|
-
)
|
|
172
|
+
connection.execute({
|
|
173
|
+
portal: this.portal,
|
|
174
|
+
rows: rows,
|
|
175
|
+
})
|
|
186
176
|
connection.flush()
|
|
187
177
|
}
|
|
188
178
|
|
|
179
|
+
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
|
|
189
180
|
prepare(connection) {
|
|
190
181
|
// prepared statements need sync to be called after each command
|
|
191
182
|
// complete or when an error is encountered
|
|
192
183
|
this.isPreparedStatement = true
|
|
184
|
+
|
|
193
185
|
// TODO refactor this poor encapsulation
|
|
194
186
|
if (!this.hasBeenParsed(connection)) {
|
|
195
|
-
connection.parse(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
},
|
|
201
|
-
true
|
|
202
|
-
)
|
|
187
|
+
connection.parse({
|
|
188
|
+
text: this.text,
|
|
189
|
+
name: this.name,
|
|
190
|
+
types: this.types,
|
|
191
|
+
})
|
|
203
192
|
}
|
|
204
193
|
|
|
205
194
|
if (this.values) {
|
|
@@ -211,24 +200,17 @@ class Query extends EventEmitter {
|
|
|
211
200
|
}
|
|
212
201
|
}
|
|
213
202
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
connection.describe(
|
|
226
|
-
{
|
|
227
|
-
type: 'P',
|
|
228
|
-
name: this.portal || '',
|
|
229
|
-
},
|
|
230
|
-
true
|
|
231
|
-
)
|
|
203
|
+
connection.bind({
|
|
204
|
+
portal: this.portal,
|
|
205
|
+
statement: this.name,
|
|
206
|
+
values: this.values,
|
|
207
|
+
binary: this.binary,
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
connection.describe({
|
|
211
|
+
type: 'P',
|
|
212
|
+
name: this.portal || '',
|
|
213
|
+
})
|
|
232
214
|
|
|
233
215
|
this._getRows(connection, this.rows)
|
|
234
216
|
}
|
package/lib/result.js
CHANGED
|
@@ -1,103 +1,98 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* README.md file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
2
|
|
|
10
3
|
var types = require('pg-types')
|
|
11
4
|
|
|
5
|
+
var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/
|
|
6
|
+
|
|
12
7
|
// result object returned from query
|
|
13
8
|
// in the 'end' event and also
|
|
14
9
|
// passed as second argument to provided callback
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/
|
|
31
|
-
|
|
32
|
-
// adds a command complete message
|
|
33
|
-
Result.prototype.addCommandComplete = function (msg) {
|
|
34
|
-
var match
|
|
35
|
-
if (msg.text) {
|
|
36
|
-
// pure javascript
|
|
37
|
-
match = matchRegexp.exec(msg.text)
|
|
38
|
-
} else {
|
|
39
|
-
// native bindings
|
|
40
|
-
match = matchRegexp.exec(msg.command)
|
|
41
|
-
}
|
|
42
|
-
if (match) {
|
|
43
|
-
this.command = match[1]
|
|
44
|
-
if (match[3]) {
|
|
45
|
-
// COMMMAND OID ROWS
|
|
46
|
-
this.oid = parseInt(match[2], 10)
|
|
47
|
-
this.rowCount = parseInt(match[3], 10)
|
|
48
|
-
} else if (match[2]) {
|
|
49
|
-
// COMMAND ROWS
|
|
50
|
-
this.rowCount = parseInt(match[2], 10)
|
|
10
|
+
class Result {
|
|
11
|
+
constructor(rowMode, types) {
|
|
12
|
+
this.command = null
|
|
13
|
+
this.rowCount = null
|
|
14
|
+
this.oid = null
|
|
15
|
+
this.rows = []
|
|
16
|
+
this.fields = []
|
|
17
|
+
this._parsers = undefined
|
|
18
|
+
this._types = types
|
|
19
|
+
this.RowCtor = null
|
|
20
|
+
this.rowAsArray = rowMode === 'array'
|
|
21
|
+
if (this.rowAsArray) {
|
|
22
|
+
this.parseRow = this._parseRowAsArray
|
|
51
23
|
}
|
|
52
24
|
}
|
|
53
|
-
}
|
|
54
25
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
26
|
+
// adds a command complete message
|
|
27
|
+
addCommandComplete(msg) {
|
|
28
|
+
var match
|
|
29
|
+
if (msg.text) {
|
|
30
|
+
// pure javascript
|
|
31
|
+
match = matchRegexp.exec(msg.text)
|
|
61
32
|
} else {
|
|
62
|
-
|
|
33
|
+
// native bindings
|
|
34
|
+
match = matchRegexp.exec(msg.command)
|
|
35
|
+
}
|
|
36
|
+
if (match) {
|
|
37
|
+
this.command = match[1]
|
|
38
|
+
if (match[3]) {
|
|
39
|
+
// COMMMAND OID ROWS
|
|
40
|
+
this.oid = parseInt(match[2], 10)
|
|
41
|
+
this.rowCount = parseInt(match[3], 10)
|
|
42
|
+
} else if (match[2]) {
|
|
43
|
+
// COMMAND ROWS
|
|
44
|
+
this.rowCount = parseInt(match[2], 10)
|
|
45
|
+
}
|
|
63
46
|
}
|
|
64
47
|
}
|
|
65
|
-
return row
|
|
66
|
-
}
|
|
67
48
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
49
|
+
_parseRowAsArray(rowData) {
|
|
50
|
+
var row = new Array(rowData.length)
|
|
51
|
+
for (var i = 0, len = rowData.length; i < len; i++) {
|
|
52
|
+
var rawValue = rowData[i]
|
|
53
|
+
if (rawValue !== null) {
|
|
54
|
+
row[i] = this._parsers[i](rawValue)
|
|
55
|
+
} else {
|
|
56
|
+
row[i] = null
|
|
57
|
+
}
|
|
77
58
|
}
|
|
59
|
+
return row
|
|
78
60
|
}
|
|
79
|
-
return row
|
|
80
|
-
}
|
|
81
61
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
62
|
+
parseRow(rowData) {
|
|
63
|
+
var row = {}
|
|
64
|
+
for (var i = 0, len = rowData.length; i < len; i++) {
|
|
65
|
+
var rawValue = rowData[i]
|
|
66
|
+
var field = this.fields[i].name
|
|
67
|
+
if (rawValue !== null) {
|
|
68
|
+
row[field] = this._parsers[i](rawValue)
|
|
69
|
+
} else {
|
|
70
|
+
row[field] = null
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return row
|
|
74
|
+
}
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// multiple query statements in 1 action can result in multiple sets
|
|
89
|
-
// of rowDescriptions...eg: 'select NOW(); select 1::int;'
|
|
90
|
-
// you need to reset the fields
|
|
91
|
-
this.fields = fieldDescriptions
|
|
92
|
-
if (this.fields.length) {
|
|
93
|
-
this._parsers = new Array(fieldDescriptions.length)
|
|
76
|
+
addRow(row) {
|
|
77
|
+
this.rows.push(row)
|
|
94
78
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
79
|
+
|
|
80
|
+
addFields(fieldDescriptions) {
|
|
81
|
+
// clears field definitions
|
|
82
|
+
// multiple query statements in 1 action can result in multiple sets
|
|
83
|
+
// of rowDescriptions...eg: 'select NOW(); select 1::int;'
|
|
84
|
+
// you need to reset the fields
|
|
85
|
+
this.fields = fieldDescriptions
|
|
86
|
+
if (this.fields.length) {
|
|
87
|
+
this._parsers = new Array(fieldDescriptions.length)
|
|
88
|
+
}
|
|
89
|
+
for (var i = 0; i < fieldDescriptions.length; i++) {
|
|
90
|
+
var desc = fieldDescriptions[i]
|
|
91
|
+
if (this._types) {
|
|
92
|
+
this._parsers[i] = this._types.getTypeParser(desc.dataTypeID, desc.format || 'text')
|
|
93
|
+
} else {
|
|
94
|
+
this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || 'text')
|
|
95
|
+
}
|
|
101
96
|
}
|
|
102
97
|
}
|
|
103
98
|
}
|
package/lib/type-overrides.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* README.md file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
2
|
|
|
10
3
|
var types = require('pg-types')
|
|
11
4
|
|
package/lib/utils.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com)
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* README.md file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
2
|
|
|
10
3
|
const crypto = require('crypto')
|
|
11
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "PostgreSQL client - pure javascript & libpq with the same API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -21,12 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"buffer-writer": "2.0.0",
|
|
23
23
|
"packet-reader": "1.0.0",
|
|
24
|
-
"pg-connection-string": "^2.
|
|
24
|
+
"pg-connection-string": "^2.4.0",
|
|
25
25
|
"pg-pool": "^3.2.1",
|
|
26
|
-
"pg-protocol": "^1.
|
|
26
|
+
"pg-protocol": "^1.3.0",
|
|
27
27
|
"pg-types": "^2.1.0",
|
|
28
|
-
"pgpass": "1.x"
|
|
29
|
-
"semver": "4.3.2"
|
|
28
|
+
"pgpass": "1.x"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"async": "0.9.0",
|
|
@@ -34,7 +33,14 @@
|
|
|
34
33
|
"co": "4.6.0",
|
|
35
34
|
"pg-copy-streams": "0.3.0"
|
|
36
35
|
},
|
|
37
|
-
"
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"pg-native": ">=2.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"pg-native": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
38
44
|
"scripts": {
|
|
39
45
|
"test": "make test-all"
|
|
40
46
|
},
|
|
@@ -46,5 +52,5 @@
|
|
|
46
52
|
"engines": {
|
|
47
53
|
"node": ">= 8.0.0"
|
|
48
54
|
},
|
|
49
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "7ffe68eba056b9a6d0fa88f928aa85e768c28838"
|
|
50
56
|
}
|