diff --git a/packages/pg-native/index.js b/packages/pg-native/index.js index 7fcc26303..fafd66aaf 100644 --- a/packages/pg-native/index.js +++ b/packages/pg-native/index.js @@ -174,8 +174,8 @@ Client.prototype._stopReading = function () { this.pq.removeListener('readable', this._read) } -Client.prototype._consumeQueryResults = function (pq) { - return buildResult(pq, this._types, this.arrayMode) +Client.prototype._consumeQueryResults = function (pq, arrayMode = this.arrayMode) { + return buildResult(pq, this._types, arrayMode) } Client.prototype._emitResult = function (pq) { @@ -441,7 +441,7 @@ Client.prototype._readPipelineResults = function (queries, cb) { } if (status === 'PGRES_TUPLES_OK' || status === 'PGRES_COMMAND_OK' || status === 'PGRES_EMPTY_QUERY') { - currentResult = self._consumeQueryResults(pq) + currentResult = self._consumeQueryResults(pq, queries[queryIndex].arrayMode) continue } } diff --git a/packages/pg/lib/native/client.js b/packages/pg/lib/native/client.js index d305713d6..2edfff720 100644 --- a/packages/pg/lib/native/client.js +++ b/packages/pg/lib/native/client.js @@ -337,7 +337,7 @@ Client.prototype._pulsePipelinedQueryQueue = function () { nativeQueries.push(query) const values = query.values ? query.values.map(utils.prepareValue) : null - const pipelineEntry = { text: query.text, name: query.name } + const pipelineEntry = { text: query.text, name: query.name, arrayMode: query._arrayMode } if (values) { pipelineEntry.values = values } diff --git a/packages/pg/test/integration/client/pipelining-tests.js b/packages/pg/test/integration/client/pipelining-tests.js index 957047d7d..7f927d2b0 100644 --- a/packages/pg/test/integration/client/pipelining-tests.js +++ b/packages/pg/test/integration/client/pipelining-tests.js @@ -35,6 +35,21 @@ suite.test('pipeline with parameterized queries', async function () { await client.end() }) +suite.test('pipeline preserves row mode for each query', async function () { + const client = new helper.Client({ pipeline: true }) + await client.connect() + + const [arrayResult, objectResult] = await Promise.all([ + client.query({ text: 'SELECT $1::int AS num', values: [10], rowMode: 'array' }), + client.query({ text: 'SELECT $1::int AS num', values: [20] }), + ]) + + assert.deepStrictEqual(arrayResult.rows, [[10]]) + assert.deepStrictEqual(objectResult.rows, [{ num: 20 }]) + + await client.end() +}) + suite.test('pipeline with named prepared statements', async function () { const client = helper.client(undefined, { pipeline: true })