pg 8.4.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.
Files changed (2) hide show
  1. package/lib/query.js +27 -21
  2. package/package.json +2 -2
package/lib/query.js CHANGED
@@ -96,39 +96,28 @@ class Query extends EventEmitter {
96
96
  }
97
97
  }
98
98
 
99
- handleCommandComplete(msg, con) {
99
+ handleCommandComplete(msg, connection) {
100
100
  this._checkForMultirow()
101
101
  this._result.addCommandComplete(msg)
102
102
  // need to sync after each command complete of a prepared statement
103
- if (this.isPreparedStatement) {
104
- con.sync()
103
+ // if we were using a row count which results in multiple calls to _getRows
104
+ if (this.rows) {
105
+ connection.sync()
105
106
  }
106
107
  }
107
108
 
108
109
  // if a named prepared statement is created with empty query text
109
110
  // the backend will send an emptyQuery message but *not* a command complete message
110
- // execution on the connection will hang until the backend receives a sync message
111
- handleEmptyQuery(con) {
112
- if (this.isPreparedStatement) {
113
- con.sync()
114
- }
115
- }
116
-
117
- handleReadyForQuery(con) {
118
- if (this._canceledDueToError) {
119
- return this.handleError(this._canceledDueToError, con)
120
- }
121
- if (this.callback) {
122
- 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()
123
116
  }
124
- this.emit('end', this._results)
125
117
  }
126
118
 
127
119
  handleError(err, connection) {
128
120
  // need to sync after error during a prepared statement
129
- if (this.isPreparedStatement) {
130
- connection.sync()
131
- }
132
121
  if (this._canceledDueToError) {
133
122
  err = this._canceledDueToError
134
123
  this._canceledDueToError = false
@@ -141,6 +130,16 @@ class Query extends EventEmitter {
141
130
  this.emit('error', err)
142
131
  }
143
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
+
144
143
  submit(connection) {
145
144
  if (typeof this.text !== 'string' && typeof this.name !== 'string') {
146
145
  return new Error('A query must have either text or a name. Supplying neither is unsupported.')
@@ -173,7 +172,14 @@ class Query extends EventEmitter {
173
172
  portal: this.portal,
174
173
  rows: rows,
175
174
  })
176
- connection.flush()
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
+ }
177
183
  }
178
184
 
179
185
  // http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg",
3
- "version": "8.4.0",
3
+ "version": "8.4.1",
4
4
  "description": "PostgreSQL client - pure javascript & libpq with the same API",
5
5
  "keywords": [
6
6
  "database",
@@ -52,5 +52,5 @@
52
52
  "engines": {
53
53
  "node": ">= 8.0.0"
54
54
  },
55
- "gitHead": "7ffe68eba056b9a6d0fa88f928aa85e768c28838"
55
+ "gitHead": "36342c9a84b68123f666879a9f34ac319a44727a"
56
56
  }