Skip to content
Closed
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
46 changes: 46 additions & 0 deletions packages/pg/lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,52 @@ class Connection extends EventEmitter {
this._send(serialize.query(text))
}

// query using single batch of packets
// https://github.com/brianc/node-postgres/issues/3325
queryWithPacketBatching(query, valueMapper) {
const packets = []

if (!query.hasBeenParsed(this)) {
packets.push(
serialize.parse({
text: query.text,
name: query.name,
types: query.types,
})
)
}

packets.push(
serialize.bind({
portal: query.portal,
statement: query.name,
values: query.values,
binary: query.binary,
valueMapper: valueMapper,
})
)

packets.push(
serialize.describe({
type: 'P',
name: query.portal || '',
})
)

packets.push(
serialize.execute({
portal: query.portal,
rows: query.rows,
})
)

if (!query.rows) {
packets.push(syncBuffer)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the Flush message when query.rows is present?


this._send(Buffer.concat(packets))
}

// send parse message
parse(query) {
this._send(serialize.parse(query))
Expand Down
2 changes: 1 addition & 1 deletion packages/pg/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Query extends EventEmitter {
return new Error('Query values must be an array')
}
if (this.requiresPreparation()) {
this.prepare(connection)
connection.queryWithPacketBatching(this, utils.prepareValue)
} else {
connection.query(this.text)
}
Expand Down
Loading