mirror of
https://github.com/brianc/node-postgres.git
synced 2026-02-01 16:47:23 +00:00
Merge branch 'master' of https://github.com/juneidysoo/node-pg-cursor into juneidysoo-master
This commit is contained in:
commit
e20d0128fc
26
index.js
26
index.js
@ -19,10 +19,23 @@ function Cursor(text, values, config) {
|
|||||||
this._cb = null
|
this._cb = null
|
||||||
this._rows = null
|
this._rows = null
|
||||||
this._portal = null
|
this._portal = null
|
||||||
|
this._ifNoData = this._ifNoData.bind(this)
|
||||||
|
this._rowDescription = this._rowDescription.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(Cursor, EventEmitter)
|
util.inherits(Cursor, EventEmitter)
|
||||||
|
|
||||||
|
Cursor.prototype._ifNoData = function() {
|
||||||
|
this.state = 'idle'
|
||||||
|
this._shiftQueue()
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor.prototype._rowDescription = function() {
|
||||||
|
if (this.connection) {
|
||||||
|
this.connection.removeListener('noData', this._ifNoData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Cursor.prototype.submit = function(connection) {
|
Cursor.prototype.submit = function(connection) {
|
||||||
this.connection = connection
|
this.connection = connection
|
||||||
this._portal = 'C_' + nextUniqueID++
|
this._portal = 'C_' + nextUniqueID++
|
||||||
@ -54,19 +67,12 @@ Cursor.prototype.submit = function(connection) {
|
|||||||
|
|
||||||
con.flush()
|
con.flush()
|
||||||
|
|
||||||
const ifNoData = () => {
|
|
||||||
this.state = 'idle'
|
|
||||||
this._shiftQueue()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._conf.types) {
|
if (this._conf.types) {
|
||||||
this._result._getTypeParser = this._conf.types.getTypeParser
|
this._result._getTypeParser = this._conf.types.getTypeParser
|
||||||
}
|
}
|
||||||
|
|
||||||
con.once('noData', ifNoData)
|
con.once('noData', this._ifNoData)
|
||||||
con.once('rowDescription', () => {
|
con.once('rowDescription', this._rowDescription)
|
||||||
con.removeListener('noData', ifNoData)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor.prototype._shiftQueue = function() {
|
Cursor.prototype._shiftQueue = function() {
|
||||||
@ -132,6 +138,8 @@ Cursor.prototype.handleEmptyQuery = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Cursor.prototype.handleError = function(msg) {
|
Cursor.prototype.handleError = function(msg) {
|
||||||
|
this.connection.removeListener('noData', this._ifNoData)
|
||||||
|
this.connection.removeListener('rowDescription', this._rowDescription)
|
||||||
this.state = 'error'
|
this.state = 'error'
|
||||||
this._error = msg
|
this._error = msg
|
||||||
// satisfy any waiting callback
|
// satisfy any waiting callback
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user