Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/pg-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pg/lib/native/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions packages/pg/test/integration/client/pipelining-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down
Loading