Skip to content

Commit 0fa5cd8

Browse files
author
alxndrsn
committed
Merge branch 'master' into eslint-no-unreachable
2 parents b3e4e16 + 88311c1 commit 0fa5cd8

27 files changed

+217
-238
lines changed

.devcontainer/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
44
#-------------------------------------------------------------------------------------------------------------
55

6-
FROM node:12
6+
FROM node:20
77

88
# Avoid warnings by switching to noninteractive
99
ENV DEBIAN_FRONTEND=noninteractive

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
22
{
3-
"name": "Node.js 12 & Postgres",
3+
"name": "Node.js 20 & Postgres",
44
"dockerComposeFile": "docker-compose.yml",
55
"service": "web",
66
"workspaceFolder": "/workspace",

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
- '18'
4343
- '20'
4444
- '22'
45+
- '23'
4546
os:
4647
- ubuntu-latest
4748
name: Node.js ${{ matrix.node }}

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ For richer information consult the commit log on github with referenced pull req
44

55
We do not include break-fix version release in this file.
66

7+
8+
9+
- Add ability to specify query timeout on [per-query basis](https://github.com/brianc/node-postgres/pull/3074).
10+
711
812

913
- Add `queryMode` config option to [force use of the extended query protocol](https://github.com/brianc/node-postgres/pull/3214) on queries without any parameters.

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ This repo is a monorepo which contains the core [pg](https://github.com/brianc/n
1818
- [pg-connection-string](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string)
1919
- [pg-protocol](https://github.com/brianc/node-postgres/tree/master/packages/pg-protocol)
2020

21+
## Install
22+
```
23+
npm install pg
24+
```
25+
2126
## Documentation
2227

2328
Each package in this repo should have its own readme more focused on how to develop/contribute. For overall documentation on the project and the related modules managed by this repo please see:

packages/pg-cursor/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-cursor",
3-
"version": "2.12.0",
3+
"version": "2.12.3",
44
"description": "Query cursor extension for node-postgres",
55
"main": "index.js",
66
"directories": {
@@ -18,7 +18,7 @@
1818
"license": "MIT",
1919
"devDependencies": {
2020
"mocha": "^10.5.2",
21-
"pg": "^8.13.0"
21+
"pg": "^8.13.3"
2222
},
2323
"peerDependencies": {
2424
"pg": "^8"

packages/pg-native/bench/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var warmup = function (fn, cb) {
1919
var native = Native()
2020
native.connectSync()
2121

22-
var queryText = 'SELECT generate_series(0, 1000)'
22+
var queryText = 'SELECT generate_series(0, 1000) as X, generate_series(0, 1000) as Y, generate_series(0, 1000) as Z'
2323
var client = new pg.Client()
2424
client.connect(function () {
2525
var pure = function (cb) {
@@ -36,12 +36,12 @@ client.connect(function () {
3636
}
3737

3838
var run = function () {
39-
var start = Date.now()
39+
console.time('pure')
4040
warmup(pure, function () {
41-
console.log('pure done', Date.now() - start)
42-
start = Date.now()
41+
console.timeEnd('pure')
42+
console.time('native')
4343
warmup(nativeQuery, function () {
44-
console.log('native done', Date.now() - start)
44+
console.timeEnd('native')
4545
})
4646
})
4747
}

packages/pg-native/lib/build-result.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Result {
99
this.rowCount = undefined
1010
this.fields = []
1111
this.rows = []
12+
this._prebuiltEmptyResultObject = null
1213
}
1314

1415
consumeCommand(pq) {
@@ -18,46 +19,47 @@ class Result {
1819

1920
consumeFields(pq) {
2021
const nfields = pq.nfields()
22+
this.fields = new Array(nfields)
23+
var row = {}
2124
for (var x = 0; x < nfields; x++) {
22-
this.fields.push({
23-
name: pq.fname(x),
25+
var name = pq.fname(x)
26+
row[name] = null
27+
this.fields[x] = {
28+
name: name,
2429
dataTypeID: pq.ftype(x),
25-
})
30+
}
2631
}
32+
this._prebuiltEmptyResultObject = { ...row }
2733
}
2834

2935
consumeRows(pq) {
3036
const tupleCount = pq.ntuples()
37+
this.rows = new Array(tupleCount)
3138
for (var i = 0; i < tupleCount; i++) {
32-
const row = this._arrayMode ? this.consumeRowAsArray(pq, i) : this.consumeRowAsObject(pq, i)
33-
this.rows.push(row)
39+
this.rows[i] = this._arrayMode ? this.consumeRowAsArray(pq, i) : this.consumeRowAsObject(pq, i)
3440
}
3541
}
3642

3743
consumeRowAsObject(pq, rowIndex) {
38-
const row = {}
44+
const row = { ...this._prebuiltEmptyResultObject }
3945
for (var j = 0; j < this.fields.length; j++) {
40-
const value = this.readValue(pq, rowIndex, j)
41-
row[this.fields[j].name] = value
46+
row[this.fields[j].name] = this.readValue(pq, rowIndex, j)
4247
}
4348
return row
4449
}
4550

4651
consumeRowAsArray(pq, rowIndex) {
47-
const row = []
52+
const row = new Array(this.fields.length)
4853
for (var j = 0; j < this.fields.length; j++) {
49-
const value = this.readValue(pq, rowIndex, j)
50-
row.push(value)
54+
row[j] = this.readValue(pq, rowIndex, j)
5155
}
5256
return row
5357
}
5458

5559
readValue(pq, rowIndex, colIndex) {
5660
var rawValue = pq.getvalue(rowIndex, colIndex)
57-
if (rawValue === '') {
58-
if (pq.getisnull(rowIndex, colIndex)) {
59-
return null
60-
}
61+
if (rawValue === '' && pq.getisnull(rowIndex, colIndex)) {
62+
return null
6163
}
6264
const dataTypeId = this.fields[colIndex].dataTypeID
6365
return this._types.getTypeParser(dataTypeId)(rawValue)

packages/pg-native/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "pg-native",
3-
"version": "3.2.0",
3+
"version": "3.2.2",
44
"description": "A slightly nicer interface to Postgres over node-libpq",
55
"main": "index.js",
66
"scripts": {
77
"test": "mocha"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git://github.com/brianc/node-pg-native.git"
11+
"url": "https://github.com/brianc/node-postgres.git"
1212
},
1313
"keywords": [
1414
"postgres",
@@ -18,18 +18,18 @@
1818
"author": "Brian M. Carlson",
1919
"license": "MIT",
2020
"bugs": {
21-
"url": "https://github.com/brianc/node-pg-native/issues"
21+
"url": "https://github.com/brianc/node-postgres/issues"
2222
},
23-
"homepage": "https://github.com/brianc/node-pg-native",
23+
"homepage": "https://github.com/brianc/node-postgres/tree/master/packages/pg-native",
2424
"dependencies": {
25-
"libpq": "1.8.13",
26-
"pg-types": "^1.12.1"
25+
"libpq": "1.8.14",
26+
"pg-types": "^2.1.0"
2727
},
2828
"devDependencies": {
2929
"async": "^0.9.0",
3030
"concat-stream": "^1.4.6",
3131
"generic-pool": "^2.1.1",
32-
"lodash": "^2.4.1",
32+
"lodash": "^4.17.21",
3333
"mocha": "10.5.2",
3434
"node-gyp": ">=10.x",
3535
"okay": "^0.3.0",

packages/pg-pool/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pool
265265

266266
#### acquire
267267

268-
Fired whenever the a client is acquired from the pool
268+
Fired whenever a client is acquired from the pool
269269

270270
Example:
271271

packages/pg-pool/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class Pool extends EventEmitter {
244244
// remove the dead client from our list of clients
245245
this._clients = this._clients.filter((c) => c !== client)
246246
if (timeoutHit) {
247-
err.message = 'Connection terminated due to connection timeout'
247+
err = new Error('Connection terminated due to connection timeout', { cause: err })
248248
}
249249

250250
// this client won’t be released, so move on immediately

packages/pg-pool/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-pool",
3-
"version": "3.7.0",
3+
"version": "3.7.1",
44
"description": "Connection pool for node-postgres",
55
"main": "index.js",
66
"directories": {

packages/pg-protocol/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-protocol",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "The postgres client/server binary protocol, implemented in TypeScript",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/pg-protocol/src/buffer-reader.ts

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export class BufferReader {
3131
return result
3232
}
3333

34+
public uint32(): number {
35+
const result = this.buffer.readUInt32BE(this.offset)
36+
this.offset += 4
37+
return result
38+
}
39+
3440
public string(length: number): string {
3541
const result = this.buffer.toString(this.encoding, this.offset, this.offset + length)
3642
this.offset += length

packages/pg-protocol/src/inbound-parser.test.ts

+40-10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ var twoRowBuf = buffers.rowDescription([
3939
},
4040
])
4141

42+
var rowWithBigOids = {
43+
name: 'bigoid',
44+
tableID: 3000000001,
45+
attributeNumber: 2,
46+
dataTypeID: 3000000003,
47+
dataTypeSize: 4,
48+
typeModifier: 5,
49+
formatCode: 0,
50+
}
51+
var bigOidDescBuff = buffers.rowDescription([rowWithBigOids])
52+
4253
var emptyRowFieldBuf = new BufferList().addInt16(0).join(true, 'D')
4354

4455
var emptyRowFieldBuf = buffers.dataRow([])
@@ -132,6 +143,22 @@ var expectedTwoRowMessage = {
132143
},
133144
],
134145
}
146+
var expectedBigOidMessage = {
147+
name: 'rowDescription',
148+
length: 31,
149+
fieldCount: 1,
150+
fields: [
151+
{
152+
name: 'bigoid',
153+
tableID: 3000000001,
154+
columnID: 2,
155+
dataTypeID: 3000000003,
156+
dataTypeSize: 4,
157+
dataTypeModifier: 5,
158+
format: 'text',
159+
},
160+
],
161+
}
135162

136163
var emptyParameterDescriptionBuffer = new BufferList()
137164
.addInt16(0) // number of parameters
@@ -163,7 +190,7 @@ var expectedTwoParameterMessage = {
163190
}
164191

165192
var testForMessage = function (buffer: Buffer, expectedMessage: any) {
166-
it('recieves and parses ' + expectedMessage.name, async () => {
193+
it('receives and parses ' + expectedMessage.name, async () => {
167194
const messages = await parseBuffers([buffer])
168195
const [lastMessage] = messages
169196

@@ -261,6 +288,7 @@ describe('PgPacketStream', function () {
261288
testForMessage(emptyRowDescriptionBuffer, expectedEmptyRowDescriptionMessage)
262289
testForMessage(oneRowDescBuff, expectedOneRowMessage)
263290
testForMessage(twoRowBuf, expectedTwoRowMessage)
291+
testForMessage(bigOidDescBuff, expectedBigOidMessage)
264292
})
265293

266294
describe('parameterDescription messages', function () {
@@ -459,12 +487,12 @@ describe('PgPacketStream', function () {
459487
assert.equal(message.fields[4], '!')
460488
})
461489

462-
var testMessageRecievedAfterSpiltAt = async function (split: number) {
490+
var testMessageReceivedAfterSplitAt = async function (split: number) {
463491
var firstBuffer = Buffer.alloc(fullBuffer.length - split)
464492
var secondBuffer = Buffer.alloc(fullBuffer.length - firstBuffer.length)
465493
fullBuffer.copy(firstBuffer, 0, 0)
466494
fullBuffer.copy(secondBuffer, 0, firstBuffer.length)
467-
const messages = await parseBuffers([fullBuffer])
495+
const messages = await parseBuffers([firstBuffer, secondBuffer])
468496
const message = messages[0] as any
469497
assert.equal(message.fields.length, 5)
470498
assert.equal(message.fields[0], null)
@@ -475,17 +503,19 @@ describe('PgPacketStream', function () {
475503
}
476504

477505
it('parses when split in the middle', function () {
478-
testMessageRecievedAfterSpiltAt(6)
506+
return testMessageReceivedAfterSplitAt(6)
479507
})
480508

481509
it('parses when split at end', function () {
482-
testMessageRecievedAfterSpiltAt(2)
510+
return testMessageReceivedAfterSplitAt(2)
483511
})
484512

485513
it('parses when split at beginning', function () {
486-
testMessageRecievedAfterSpiltAt(fullBuffer.length - 2)
487-
testMessageRecievedAfterSpiltAt(fullBuffer.length - 1)
488-
testMessageRecievedAfterSpiltAt(fullBuffer.length - 5)
514+
return Promise.all([
515+
testMessageReceivedAfterSplitAt(fullBuffer.length - 2),
516+
testMessageReceivedAfterSplitAt(fullBuffer.length - 1),
517+
testMessageReceivedAfterSplitAt(fullBuffer.length - 5),
518+
])
489519
})
490520
})
491521

@@ -512,7 +542,7 @@ describe('PgPacketStream', function () {
512542
})
513543
}
514544
// sanity check
515-
it('recieves both messages when packet is not split', async function () {
545+
it('receives both messages when packet is not split', async function () {
516546
const messages = await parseBuffers([fullBuffer])
517547
verifyMessages(messages)
518548
})
@@ -526,7 +556,7 @@ describe('PgPacketStream', function () {
526556
verifyMessages(messages)
527557
}
528558

529-
describe('recieves both messages when packet is split', function () {
559+
describe('receives both messages when packet is split', function () {
530560
it('in the middle', function () {
531561
return splitAndVerifyTwoMessages(11)
532562
})

packages/pg-protocol/src/parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ export class Parser {
258258

259259
private parseField(): Field {
260260
const name = this.reader.cstring()
261-
const tableID = this.reader.int32()
261+
const tableID = this.reader.uint32()
262262
const columnID = this.reader.int16()
263-
const dataTypeID = this.reader.int32()
263+
const dataTypeID = this.reader.uint32()
264264
const dataTypeSize = this.reader.int16()
265265
const dataTypeModifier = this.reader.int32()
266266
const mode = this.reader.int16() === 0 ? 'text' : 'binary'

0 commit comments

Comments
 (0)