Skip to content

Commit 3e5db60

Browse files
committed
Merge remote-tracking branch 'origin/master' into bmc/perf/faster-bind
2 parents 18919ea + 52dfca4 commit 3e5db60

32 files changed

+1543
-1011
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ matrix:
5757
addons:
5858
postgresql: '9.6'
5959

60+
# only run lint on latest Node LTS
61+
- node_js: lts/*
62+
script: yarn lint
63+
6064
# PostgreSQL 9.2 only works on precise
6165
- node_js: lts/carbon
6266
addons:

.yarnrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--install.ignore-engines true

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
- Switch to optional peer dependencies & remove [semver](https://github.com/brianc/node-postgres/commit/a02dfac5ad2e2abf0dc3a9817f953938acdc19b1) package which has been a small thorn in the side of a few users.
10+
- Export `DatabaseError` from [pg-protocol](https://github.com/brianc/node-postgres/commit/58258430d52ee446721cc3e6611e26f8bcaa67f5).
11+
- Add support for `ssl-mode` in the [connection string](https://github.com/brianc/node-postgres/commit/6be3b9022f83efc721596cc41165afaa07bfceb0).
12+
713
814

915
- Support passing a [string of command line options flags](https://github.com/brianc/node-postgres/pull/2216) via the `{ options: string }` field on client/pool config.

README.md

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<span class="badge-npmversion"><a href="https://npmjs.org/package/pg" title="View this project on NPM"><img src="https://img.shields.io/npm/v/pg.svg" alt="NPM version" /></a></span>
66
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/pg" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/pg.svg" alt="NPM downloads" /></a></span>
77

8-
Non-blocking PostgreSQL client for Node.js. Pure JavaScript and optional native libpq bindings.
8+
Non-blocking PostgreSQL client for Node.js. Pure JavaScript and optional native libpq bindings.
99

1010
## Monorepo
1111

@@ -16,35 +16,36 @@ This repo is a monorepo which contains the core [pg](https://github.com/brianc/n
1616
- [pg-cursor](https://github.com/brianc/node-postgres/tree/master/packages/pg-cursor)
1717
- [pg-query-stream](https://github.com/brianc/node-postgres/tree/master/packages/pg-query-stream)
1818
- [pg-connection-string](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string)
19+
- [pg-protocol](https://github.com/brianc/node-postgres/tree/master/packages/pg-protocol)
1920

21+
## Documentation
2022

21-
## Documenation
22-
23-
Each package in this repo should have it's 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:
23+
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:
2424

2525
### :star: [Documentation](https://node-postgres.com) :star:
2626

2727
### Features
2828

29-
* Pure JavaScript client and native libpq bindings share _the same API_
30-
* Connection pooling
31-
* Extensible JS ↔ PostgreSQL data-type coercion
32-
* Supported PostgreSQL features
33-
* Parameterized queries
34-
* Named statements with query plan caching
35-
* Async notifications with `LISTEN/NOTIFY`
36-
* Bulk import & export with `COPY TO/COPY FROM`
29+
- Pure JavaScript client and native libpq bindings share _the same API_
30+
- Connection pooling
31+
- Extensible JS ↔ PostgreSQL data-type coercion
32+
- Supported PostgreSQL features
33+
- Parameterized queries
34+
- Named statements with query plan caching
35+
- Async notifications with `LISTEN/NOTIFY`
36+
- Bulk import & export with `COPY TO/COPY FROM`
3737

3838
### Extras
3939

40-
node-postgres is by design pretty light on abstractions. These are some handy modules we've been using over the years to complete the picture.
40+
node-postgres is by design pretty light on abstractions. These are some handy modules we've been using over the years to complete the picture.
4141
The entire list can be found on our [wiki](https://github.com/brianc/node-postgres/wiki/Extras).
4242

4343
## Support
4444

45-
node-postgres is free software. If you encounter a bug with the library please open an issue on the [GitHub repo](https://github.com/brianc/node-postgres). If you have questions unanswered by the documentation please open an issue pointing out how the documentation was unclear & I will do my best to make it better!
45+
node-postgres is free software. If you encounter a bug with the library please open an issue on the [GitHub repo](https://github.com/brianc/node-postgres). If you have questions unanswered by the documentation please open an issue pointing out how the documentation was unclear & I will do my best to make it better!
4646

4747
When you open an issue please provide:
48+
4849
- version of Node
4950
- version of Postgres
5051
- smallest possible snippet of code to reproduce the problem
@@ -56,10 +57,6 @@ You can also follow me [@briancarlson](https://twitter.com/briancarlson) if that
5657
node-postgres's continued development has been made possible in part by generous finanical support from [the community](https://github.com/brianc/node-postgres/blob/master/SPONSORS.md) and these featured sponsors:
5758

5859
<div align="center">
59-
<a href="https://www.timescale.com" target="_blank">
60-
<img height="80" src="https://node-postgres.com/timescale.svg" />
61-
</a>
62-
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAABCAQAAAB0m0auAAAADElEQVR42mNkIBIAAABSAAI2VLqiAAAAAElFTkSuQmCC" />
6360
<a href="https://crate.io" target="_blank">
6461
<img height="80" src="https://node-postgres.com/crate-io.png" />
6562
</a>
@@ -69,10 +66,11 @@ If you or your company are benefiting from node-postgres and would like to help
6966

7067
## Contributing
7168

72-
__:heart: contributions!__
69+
**:heart: contributions!**
70+
71+
I will **happily** accept your pull request if it:
7372

74-
I will __happily__ accept your pull request if it:
75-
- __has tests__
73+
- **has tests**
7674
- looks reasonable
7775
- does not break backwards compatibility
7876

@@ -94,20 +92,20 @@ The causes and solutions to common errors can be found among the [Frequently Ask
9492

9593
Copyright (c) 2010-2020 Brian Carlson ([email protected])
9694

97-
Permission is hereby granted, free of charge, to any person obtaining a copy
98-
of this software and associated documentation files (the "Software"), to deal
99-
in the Software without restriction, including without limitation the rights
100-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
101-
copies of the Software, and to permit persons to whom the Software is
102-
furnished to do so, subject to the following conditions:
103-
104-
The above copyright notice and this permission notice shall be included in
105-
all copies or substantial portions of the Software.
106-
107-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
108-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
109-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
110-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
111-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
112-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
113-
THE SOFTWARE.
95+
Permission is hereby granted, free of charge, to any person obtaining a copy
96+
of this software and associated documentation files (the "Software"), to deal
97+
in the Software without restriction, including without limitation the rights
98+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+
copies of the Software, and to permit persons to whom the Software is
100+
furnished to do so, subject to the following conditions:
101+
102+
The above copyright notice and this permission notice shall be included in
103+
all copies or substantial portions of the Software.
104+
105+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
111+
THE SOFTWARE.

SPONSORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ node-postgres is made possible by the helpful contributors from the community as
3131
- Raul Murray
3232
- Simple Analytics
3333
- Trevor Linton
34+
- Ian Walter

package.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@
1010
"packages/*"
1111
],
1212
"scripts": {
13-
"test": "yarn lint && yarn lerna exec yarn test",
13+
"test": "yarn lerna exec yarn test",
1414
"build": "yarn lerna exec --scope pg-protocol yarn build",
1515
"pretest": "yarn build",
16-
"lint": "if [ -x ./node_modules/.bin/prettier ]; then eslint '*/**/*.{js,ts,tsx}'; fi;"
16+
"lint": "eslint '*/**/*.{js,ts,tsx}'"
1717
},
1818
"devDependencies": {
19-
"@typescript-eslint/eslint-plugin": "^2.27.0",
20-
"@typescript-eslint/parser": "^2.27.0",
21-
"eslint": "^6.8.0",
22-
"eslint-config-prettier": "^6.10.1",
19+
"@typescript-eslint/eslint-plugin": "^4.4.0",
20+
"@typescript-eslint/parser": "^4.4.0",
21+
"eslint": "^7.11.0",
22+
"eslint-config-prettier": "^6.12.0",
2323
"eslint-plugin-node": "^11.1.0",
24-
"eslint-plugin-prettier": "^3.1.2",
25-
"lerna": "^3.19.0"
26-
},
27-
"optionalDependencies": {
28-
"prettier": "2.0.4"
24+
"eslint-plugin-prettier": "^3.1.4",
25+
"lerna": "^3.19.0",
26+
"prettier": "2.1.2"
2927
},
3028
"prettier": {
3129
"semi": false,

packages/pg-connection-string/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function parse(str) {
6565
config.ssl = false
6666
}
6767

68-
if (config.sslcert || config.sslkey || config.sslrootcert) {
68+
if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) {
6969
config.ssl = {}
7070
}
7171

@@ -81,6 +81,23 @@ function parse(str) {
8181
config.ssl.ca = fs.readFileSync(config.sslrootcert).toString()
8282
}
8383

84+
switch (config.sslmode) {
85+
case 'disable': {
86+
config.ssl = false
87+
break
88+
}
89+
case 'prefer':
90+
case 'require':
91+
case 'verify-ca':
92+
case 'verify-full': {
93+
break
94+
}
95+
case 'no-verify': {
96+
config.ssl.rejectUnauthorized = false
97+
break
98+
}
99+
}
100+
84101
return config
85102
}
86103

packages/pg-connection-string/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-connection-string",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"description": "Functions for dealing with a PostgresSQL connection string",
55
"main": "./index.js",
66
"types": "./index.d.ts",
@@ -22,9 +22,9 @@
2222
"author": "Blaine Bublitz <[email protected]> (http://iceddev.com/)",
2323
"license": "MIT",
2424
"bugs": {
25-
"url": "https://github.com/iceddev/pg-connection-string/issues"
25+
"url": "https://github.com/brianc/node-postgres/issues"
2626
},
27-
"homepage": "https://github.com/iceddev/pg-connection-string",
27+
"homepage": "https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string",
2828
"devDependencies": {
2929
"chai": "^4.1.1",
3030
"coveralls": "^3.0.4",

packages/pg-connection-string/test/parse.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,52 @@ describe('parse', function () {
241241
})
242242
})
243243

244+
it('configuration parameter sslmode=no-verify', function () {
245+
var connectionString = 'pg:///?sslmode=no-verify'
246+
var subject = parse(connectionString)
247+
subject.ssl.should.eql({
248+
rejectUnauthorized: false,
249+
})
250+
})
251+
252+
it('configuration parameter sslmode=disable', function () {
253+
var connectionString = 'pg:///?sslmode=disable'
254+
var subject = parse(connectionString)
255+
subject.ssl.should.eql(false)
256+
})
257+
258+
it('configuration parameter sslmode=prefer', function () {
259+
var connectionString = 'pg:///?sslmode=prefer'
260+
var subject = parse(connectionString)
261+
subject.ssl.should.eql({})
262+
})
263+
264+
it('configuration parameter sslmode=require', function () {
265+
var connectionString = 'pg:///?sslmode=require'
266+
var subject = parse(connectionString)
267+
subject.ssl.should.eql({})
268+
})
269+
270+
it('configuration parameter sslmode=verify-ca', function () {
271+
var connectionString = 'pg:///?sslmode=verify-ca'
272+
var subject = parse(connectionString)
273+
subject.ssl.should.eql({})
274+
})
275+
276+
it('configuration parameter sslmode=verify-full', function () {
277+
var connectionString = 'pg:///?sslmode=verify-full'
278+
var subject = parse(connectionString)
279+
subject.ssl.should.eql({})
280+
})
281+
282+
it('configuration parameter ssl=true and sslmode=require still work with sslrootcert=/path/to/ca', function () {
283+
var connectionString = 'pg:///?ssl=true&sslrootcert=' + __dirname + '/example.ca&sslmode=require'
284+
var subject = parse(connectionString)
285+
subject.ssl.should.eql({
286+
ca: 'example ca\n',
287+
})
288+
})
289+
244290
it('allow other params like max, ...', function () {
245291
var subject = parse('pg://myhost/db?max=18&min=4')
246292
subject.max.should.equal('18')

packages/pg-cursor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-cursor",
3-
"version": "2.3.0",
3+
"version": "2.4.2",
44
"description": "Query cursor extension for node-postgres",
55
"main": "index.js",
66
"directories": {
@@ -17,6 +17,6 @@
1717
"license": "MIT",
1818
"devDependencies": {
1919
"mocha": "^7.1.2",
20-
"pg": "^8.3.0"
20+
"pg": "^8.4.2"
2121
}
2222
}

packages/pg-pool/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class Pool extends EventEmitter {
7373
value: options.password,
7474
})
7575
}
76+
if (options != null && options.ssl && options.ssl.key) {
77+
// "hiding" the ssl->key so it doesn't show up in stack traces
78+
// or if the client is console.logged
79+
Object.defineProperty(this.options.ssl, 'key', {
80+
enumerable: false,
81+
})
82+
}
7683

7784
this.options.max = this.options.max || this.options.poolSize || 10
7885
this.options.maxUses = this.options.maxUses || Infinity

packages/pg-pool/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-pool",
3-
"version": "3.2.1",
3+
"version": "3.2.2",
44
"description": "Connection pool for node-postgres",
55
"main": "index.js",
66
"directories": {

packages/pg-protocol/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# pg-protocol
2+
3+
Low level postgres wire protocol parser and serailizer written in Typescript. Used by node-postgres. Needs more documentation. :smile:

packages/pg-protocol/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-protocol",
3-
"version": "1.2.5",
3+
"version": "1.3.0",
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/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BackendMessage } from './messages'
1+
import { BackendMessage, DatabaseError } from './messages'
22
import { serialize } from './serializer'
33
import { Parser, MessageCallback } from './parser'
44

@@ -8,4 +8,4 @@ export function parse(stream: NodeJS.ReadableStream, callback: MessageCallback):
88
return new Promise((resolve) => stream.on('end', () => resolve()))
99
}
1010

11-
export { serialize }
11+
export { serialize, DatabaseError }

packages/pg-query-stream/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-query-stream",
3-
"version": "3.2.0",
3+
"version": "3.3.2",
44
"description": "Postgres query result returned as readable stream",
55
"main": "index.js",
66
"scripts": {
@@ -26,12 +26,12 @@
2626
"concat-stream": "~1.0.1",
2727
"eslint-plugin-promise": "^3.5.0",
2828
"mocha": "^7.1.2",
29-
"pg": "^8.3.0",
29+
"pg": "^8.4.2",
3030
"stream-spec": "~0.3.5",
3131
"stream-tester": "0.0.5",
3232
"through": "~2.3.4"
3333
},
3434
"dependencies": {
35-
"pg-cursor": "^2.3.0"
35+
"pg-cursor": "^2.4.2"
3636
}
3737
}

0 commit comments

Comments
 (0)