mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Add support for pg-native multi-row result
This commit is contained in:
parent
28b330c88e
commit
ac3102eea2
@ -91,7 +91,7 @@ NativeQuery.prototype.submit = function (client) {
|
||||
this.native = client.native
|
||||
client.native.arrayMode = this._arrayMode
|
||||
|
||||
var after = function (err, rows) {
|
||||
var after = function (err, rows, results) {
|
||||
client.native.arrayMode = false
|
||||
setImmediate(function () {
|
||||
self.emit('_done')
|
||||
@ -102,22 +102,26 @@ NativeQuery.prototype.submit = function (client) {
|
||||
return self.handleError(err)
|
||||
}
|
||||
|
||||
var result = new NativeResult()
|
||||
result.addCommandComplete(self.native.pq)
|
||||
result.rows = rows
|
||||
|
||||
// emit row events for each row in the result
|
||||
if (self._emitRowEvents) {
|
||||
rows.forEach(function (row) {
|
||||
self.emit('row', row, result)
|
||||
})
|
||||
if (results.length > 1) {
|
||||
rows.forEach((rowOfRows, i) => {
|
||||
rowOfRows.forEach(row => {
|
||||
self.emit('row', row, results[i])
|
||||
})
|
||||
})
|
||||
} else {
|
||||
rows.forEach(function (row) {
|
||||
self.emit('row', row, results)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// handle successful result
|
||||
self.state = 'end'
|
||||
self.emit('end', result)
|
||||
self.emit('end', results)
|
||||
if (self.callback) {
|
||||
self.callback(null, result)
|
||||
self.callback(null, results)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ var conInfo = helper.config
|
||||
|
||||
var checkResult = function (result) {
|
||||
assert(result.fields)
|
||||
console.log('YOU ARE HERE')
|
||||
console.log('result!!', result)
|
||||
assert.equal(result.fields.length, 3)
|
||||
var fields = result.fields
|
||||
assert.equal(fields[0].name, 'now')
|
||||
|
||||
@ -49,16 +49,17 @@ test('prepared statements do not mutate params', function () {
|
||||
|
||||
client.on('drain', client.end.bind(client))
|
||||
|
||||
const rows = []
|
||||
query.on('row', function (row, result) {
|
||||
assert.ok(result)
|
||||
result.addRow(row)
|
||||
rows.push(row)
|
||||
})
|
||||
|
||||
query.on('end', function (result) {
|
||||
assert.lengthIs(result.rows, 26, 'result returned wrong number of rows')
|
||||
assert.lengthIs(result.rows, result.rowCount)
|
||||
assert.equal(result.rows[0].name, 'Aaron')
|
||||
assert.equal(result.rows[25].name, 'Zanzabar')
|
||||
assert.lengthIs(rows, 26, 'result returned wrong number of rows')
|
||||
assert.lengthIs(rows, result.rowCount)
|
||||
assert.equal(rows[0].name, 'Aaron')
|
||||
assert.equal(rows[25].name, 'Zanzabar')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user