pg 8.3.0 → 8.4.1

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/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
 
@@ -103,39 +96,28 @@ class Query extends EventEmitter {
103
96
  }
104
97
  }
105
98
 
106
- handleCommandComplete(msg, con) {
99
+ handleCommandComplete(msg, connection) {
107
100
  this._checkForMultirow()
108
101
  this._result.addCommandComplete(msg)
109
102
  // need to sync after each command complete of a prepared statement
110
- if (this.isPreparedStatement) {
111
- con.sync()
103
+ // if we were using a row count which results in multiple calls to _getRows
104
+ if (this.rows) {
105
+ connection.sync()
112
106
  }
113
107
  }
114
108
 
115
109
  // if a named prepared statement is created with empty query text
116
110
  // the backend will send an emptyQuery message but *not* a command complete message
117
- // execution on the connection will hang until the backend receives a sync message
118
- handleEmptyQuery(con) {
119
- if (this.isPreparedStatement) {
120
- con.sync()
121
- }
122
- }
123
-
124
- handleReadyForQuery(con) {
125
- if (this._canceledDueToError) {
126
- return this.handleError(this._canceledDueToError, con)
127
- }
128
- if (this.callback) {
129
- this.callback(null, this._results)
111
+ // since we pipeline sync immediately after execute we don't need to do anything here
112
+ // unless we have rows specified, in which case we did not pipeline the intial sync call
113
+ handleEmptyQuery(connection) {
114
+ if (this.rows) {
115
+ connection.sync()
130
116
  }
131
- this.emit('end', this._results)
132
117
  }
133
118
 
134
119
  handleError(err, connection) {
135
120
  // need to sync after error during a prepared statement
136
- if (this.isPreparedStatement) {
137
- connection.sync()
138
- }
139
121
  if (this._canceledDueToError) {
140
122
  err = this._canceledDueToError
141
123
  this._canceledDueToError = false
@@ -148,6 +130,16 @@ class Query extends EventEmitter {
148
130
  this.emit('error', err)
149
131
  }
150
132
 
133
+ handleReadyForQuery(con) {
134
+ if (this._canceledDueToError) {
135
+ return this.handleError(this._canceledDueToError, con)
136
+ }
137
+ if (this.callback) {
138
+ this.callback(null, this._results)
139
+ }
140
+ this.emit('end', this._results)
141
+ }
142
+
151
143
  submit(connection) {
152
144
  if (typeof this.text !== 'string' && typeof this.name !== 'string') {
153
145
  return new Error('A query must have either text or a name. Supplying neither is unsupported.')
@@ -176,30 +168,33 @@ class Query extends EventEmitter {
176
168
  }
177
169
 
178
170
  _getRows(connection, rows) {
179
- connection.execute(
180
- {
181
- portal: this.portal,
182
- rows: rows,
183
- },
184
- true
185
- )
186
- connection.flush()
171
+ connection.execute({
172
+ portal: this.portal,
173
+ rows: rows,
174
+ })
175
+ // if we're not reading pages of rows send the sync command
176
+ // to indicate the pipeline is finished
177
+ if (!rows) {
178
+ connection.sync()
179
+ } else {
180
+ // otherwise flush the call out to read more rows
181
+ connection.flush()
182
+ }
187
183
  }
188
184
 
185
+ // http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
189
186
  prepare(connection) {
190
187
  // prepared statements need sync to be called after each command
191
188
  // complete or when an error is encountered
192
189
  this.isPreparedStatement = true
190
+
193
191
  // TODO refactor this poor encapsulation
194
192
  if (!this.hasBeenParsed(connection)) {
195
- connection.parse(
196
- {
197
- text: this.text,
198
- name: this.name,
199
- types: this.types,
200
- },
201
- true
202
- )
193
+ connection.parse({
194
+ text: this.text,
195
+ name: this.name,
196
+ types: this.types,
197
+ })
203
198
  }
204
199
 
205
200
  if (this.values) {
@@ -211,24 +206,17 @@ class Query extends EventEmitter {
211
206
  }
212
207
  }
213
208
 
214
- // http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
215
- connection.bind(
216
- {
217
- portal: this.portal,
218
- statement: this.name,
219
- values: this.values,
220
- binary: this.binary,
221
- },
222
- true
223
- )
224
-
225
- connection.describe(
226
- {
227
- type: 'P',
228
- name: this.portal || '',
229
- },
230
- true
231
- )
209
+ connection.bind({
210
+ portal: this.portal,
211
+ statement: this.name,
212
+ values: this.values,
213
+ binary: this.binary,
214
+ })
215
+
216
+ connection.describe({
217
+ type: 'P',
218
+ name: this.portal || '',
219
+ })
232
220
 
233
221
  this._getRows(connection, this.rows)
234
222
  }
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
- var Result = function (rowMode, types) {
16
- this.command = null
17
- this.rowCount = null
18
- this.oid = null
19
- this.rows = []
20
- this.fields = []
21
- this._parsers = undefined
22
- this._types = types
23
- this.RowCtor = null
24
- this.rowAsArray = rowMode === 'array'
25
- if (this.rowAsArray) {
26
- this.parseRow = this._parseRowAsArray
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
- Result.prototype._parseRowAsArray = function (rowData) {
56
- var row = new Array(rowData.length)
57
- for (var i = 0, len = rowData.length; i < len; i++) {
58
- var rawValue = rowData[i]
59
- if (rawValue !== null) {
60
- row[i] = this._parsers[i](rawValue)
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
- row[i] = null
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
- Result.prototype.parseRow = function (rowData) {
69
- var row = {}
70
- for (var i = 0, len = rowData.length; i < len; i++) {
71
- var rawValue = rowData[i]
72
- var field = this.fields[i].name
73
- if (rawValue !== null) {
74
- row[field] = this._parsers[i](rawValue)
75
- } else {
76
- row[field] = null
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
- Result.prototype.addRow = function (row) {
83
- this.rows.push(row)
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
- Result.prototype.addFields = function (fieldDescriptions) {
87
- // clears field definitions
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
- for (var i = 0; i < fieldDescriptions.length; i++) {
96
- var desc = fieldDescriptions[i]
97
- if (this._types) {
98
- this._parsers[i] = this._types.getTypeParser(desc.dataTypeID, desc.format || 'text')
99
- } else {
100
- this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || 'text')
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
  }
@@ -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.0",
3
+ "version": "8.4.1",
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.3.0",
24
+ "pg-connection-string": "^2.4.0",
25
25
  "pg-pool": "^3.2.1",
26
- "pg-protocol": "^1.2.5",
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
- "minNativeVersion": "2.0.0",
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
  },
@@ -45,5 +51,6 @@
45
51
  "license": "MIT",
46
52
  "engines": {
47
53
  "node": ">= 8.0.0"
48
- }
54
+ },
55
+ "gitHead": "36342c9a84b68123f666879a9f34ac319a44727a"
49
56
  }