Skip to content

Commit d842255

Browse files
committed
Merge branch 'master' into normal-encoding-parameter
2 parents bf40f03 + bf46939 commit d842255

40 files changed

+1167
-1366
lines changed

.eslintrc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
{
2-
"plugins": [
3-
"prettier"
4-
],
2+
"plugins": ["prettier"],
53
"parser": "@typescript-eslint/parser",
6-
"extends": [
7-
"plugin:prettier/recommended",
8-
"prettier/@typescript-eslint"
9-
],
10-
"ignorePatterns": [
11-
"node_modules",
12-
"packages/pg-protocol/dist/**/*"
13-
],
4+
"extends": ["plugin:prettier/recommended", "prettier/@typescript-eslint"],
5+
"ignorePatterns": ["node_modules", "coverage", "packages/pg-protocol/dist/**/*"],
146
"parserOptions": {
157
"ecmaVersion": 2017,
168
"sourceType": "module"

.travis.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ before_script: |
77
88
env:
99
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres
10-
# test w/ new faster parsing code
11-
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres PG_FAST_CONNECTION=true
1210

1311
node_js:
1412
- lts/dubnium
1513
- lts/erbium
1614
# node 13.7 seems to have changed behavior of async iterators exiting early on streams
1715
# if 13.8 still has this problem when it comes down I'll talk to the node team about the change
18-
# in the mean time...peg to 13.6
16+
# in the mean time...peg to 13.6
1917
- 13.6
2018
- 14
2119

2220
addons:
23-
postgresql: "10"
21+
postgresql: '10'
2422

2523
matrix:
2624
include:
2725
# Run tests/paths that require password authentication
2826
- node_js: lts/erbium
2927
env:
30-
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres PGPASSWORD=test-password
28+
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres PGPASSWORD=test-password SCRAM_TEST_PGUSER=scram_test SCRAM_TEST_PGPASSWORD=test4scram
3129
before_script: |
3230
sudo -u postgres sed -i \
3331
-e '/^local/ s/trust$/peer/' \
@@ -36,28 +34,31 @@ matrix:
3634
sudo -u postgres psql -c "ALTER ROLE postgres PASSWORD 'test-password'; SELECT pg_reload_conf()"
3735
yarn build
3836
node packages/pg/script/create-test-tables.js postgresql:///
37+
sudo -u postgres -- psql \
38+
-c "SET password_encryption = 'scram-sha-256'" \
39+
-c "CREATE ROLE scram_test login password 'test4scram'"
3940
4041
- node_js: lts/carbon
4142
addons:
42-
postgresql: "9.5"
43+
postgresql: '9.5'
4344
dist: precise
4445

4546
# different PostgreSQL versions on Node LTS
4647
- node_js: lts/erbium
4748
addons:
48-
postgresql: "9.3"
49+
postgresql: '9.3'
4950
- node_js: lts/erbium
5051
addons:
51-
postgresql: "9.4"
52+
postgresql: '9.4'
5253
- node_js: lts/erbium
5354
addons:
54-
postgresql: "9.5"
55+
postgresql: '9.5'
5556
- node_js: lts/erbium
5657
addons:
57-
postgresql: "9.6"
58+
postgresql: '9.6'
5859

5960
# PostgreSQL 9.2 only works on precise
6061
- node_js: lts/carbon
6162
addons:
62-
postgresql: "9.2"
63+
postgresql: '9.2'
6364
dist: precise

CHANGELOG.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ 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+
### pg@8.2.0
8+
9+
- Switch internal protocol parser & serializer to [pg-protocol](https://github.com/brianc/node-postgres/tree/master/packages/pg-protocol). The change is backwards compatible but results in a significant performance improvement across the board, with some queries as much as 50% faster. This is the first work to land in an on-going performance improvment initiative I'm working on. Stay tuned as things are set to get much faster still! :rocket:
10+
11+
### pg-cursor@2.2.0
12+
13+
- Switch internal protocol parser & serializer to [pg-protocol](https://github.com/brianc/node-postgres/tree/master/packages/pg-protocol). The change is backwards compatible but results in a significant performance improvement across the board, with some queries as much as 50% faster.
14+
15+
### pg-query-stream@3.1.0
16+
17+
- Switch internal protocol parser & serializer to [pg-protocol](https://github.com/brianc/node-postgres/tree/master/packages/pg-protocol). The change is backwards compatible but results in a significant performance improvement across the board, with some queries as much as 50% faster.
18+
19+
### pg@8.1.0
20+
21+
- Switch to using [monorepo](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string) version of `pg-connection-string`. This includes better support for SSL argument parsing from connection strings and ensures continuity of support.
22+
- Add `&ssl=no-verify` option to connection string and `PGSSLMODE=no-verify` environment variable support for the pure JS driver. This is equivalent of passing `{ ssl: { rejectUnauthorize: false } }` to the client/pool constructor. The advantage of having support in connection strings and environment variables is it can be "externally" configured via environment variables and CLI arguments much more easily, and should remove the need to directly edit any application code for [the SSL default changes in 8.0](https://node-postgres.com/announcements#2020-02-25). This should make using `pg@8.x` significantly less difficult on environments like Heroku for example.
23+
24+
### pg-pool@3.2.0
25+
26+
- Same changes to `pg` impact `pg-pool` as they both use the same connection parameter and connection string parsing code for configuring SSL.
27+
728
### pg-pool@3.1.0
829

930
- Add [maxUses](https://github.com/brianc/node-postgres/pull/2157) config option.
@@ -12,8 +33,8 @@ We do not include break-fix version release in this file.
1233

1334
#### note: for detailed release notes please [check here](https://node-postgres.com/announcements#2020-02-25)
1435

15-
- Remove versions of node older than `6 lts` from the test matrix. `pg>=8.0` may still work on older versions but it is no longer officially supported.
16-
- Change default behavior when not specifying `rejectUnauthorized` with the SSL connection parameters. Previously we defaulted to `rejectUnauthorized: false` when it was not specifically included. We now default to `rejectUnauthorized: true.` Manually specify `{ ssl: { rejectUnauthorized: false } }` for old behavior.
36+
- Remove versions of node older than `6 lts` from the test matrix. `pg>=8.0` may still work on older versions but it is no longer officially supported.
37+
- Change default behavior when not specifying `rejectUnauthorized` with the SSL connection parameters. Previously we defaulted to `rejectUnauthorized: false` when it was not specifically included. We now default to `rejectUnauthorized: true.` Manually specify `{ ssl: { rejectUnauthorized: false } }` for old behavior.
1738
- Change [default database](https://github.com/brianc/node-postgres/pull/1679) when not specified to use the `user` config option if available. Previously `process.env.USER` was used.
1839
- Change `pg.Pool` and `pg.Query` to [be](https://github.com/brianc/node-postgres/pull/2126) an [es6 class](https://github.com/brianc/node-postgres/pull/2063).
1940
- Make `pg.native` non enumerable.
@@ -27,16 +48,17 @@ We do not include break-fix version release in this file.
2748

2849
### pg-query-stream@3.0.0
2950

30-
- [Rewrote stream internals](https://github.com/brianc/node-postgres/pull/2051) to better conform to node stream semantics. This should make pg-query-stream much better at respecting [highWaterMark](https://nodejs.org/api/stream.html#stream_new_stream_readable_options) and getting rid of some edge case bugs when using pg-query-stream as an async iterator. Due to the size and nature of this change (effectively a full re-write) it's safest to bump the semver major here, though almost all tests remain untouched and still passing, which brings us to a breaking change to the API....
31-
- Changed `stream.close` to `stream.destroy` which is the [official](https://nodejs.org/api/stream.html#stream_readable_destroy_error) way to terminate a readable stream. This is a __breaking change__ if you rely on the `stream.close` method on pg-query-stream...though should be just a find/replace type operation to upgrade as the semantics remain very similar (not exactly the same, since internals are rewritten, but more in line with how streams are "supposed" to behave).
32-
- Unified the `config.batchSize` and `config.highWaterMark` to both do the same thing: control how many rows are buffered in memory. The `ReadableStream` will manage exactly how many rows are requested from the cursor at a time. This should give better out of the box performance and help with efficient async iteration.
51+
- [Rewrote stream internals](https://github.com/brianc/node-postgres/pull/2051) to better conform to node stream semantics. This should make pg-query-stream much better at respecting [highWaterMark](https://nodejs.org/api/stream.html#stream_new_stream_readable_options) and getting rid of some edge case bugs when using pg-query-stream as an async iterator. Due to the size and nature of this change (effectively a full re-write) it's safest to bump the semver major here, though almost all tests remain untouched and still passing, which brings us to a breaking change to the API....
52+
- Changed `stream.close` to `stream.destroy` which is the [official](https://nodejs.org/api/stream.html#stream_readable_destroy_error) way to terminate a readable stream. This is a **breaking change** if you rely on the `stream.close` method on pg-query-stream...though should be just a find/replace type operation to upgrade as the semantics remain very similar (not exactly the same, since internals are rewritten, but more in line with how streams are "supposed" to behave).
53+
- Unified the `config.batchSize` and `config.highWaterMark` to both do the same thing: control how many rows are buffered in memory. The `ReadableStream` will manage exactly how many rows are requested from the cursor at a time. This should give better out of the box performance and help with efficient async iteration.
3354

3455
### pg@7.17.0
3556

3657
- Add support for `idle_in_transaction_session_timeout` [option](https://github.com/brianc/node-postgres/pull/2049).
3758

3859
### 7.16.0
39-
- Add optional, opt-in behavior to test new, [faster query pipeline](https://github.com/brianc/node-postgres/pull/2044). This is experimental, and not documented yet. The pipeline changes will grow significantly after the 8.0 release.
60+
61+
- Add optional, opt-in behavior to test new, [faster query pipeline](https://github.com/brianc/node-postgres/pull/2044). This is experimental, and not documented yet. The pipeline changes will grow significantly after the 8.0 release.
4062

4163
### 7.15.0
4264

@@ -161,7 +183,7 @@ Promise support & other goodness lives now in [pg-pool](https://github.com/brian
161183
- Included support for tcp keep alive. Enable it as follows:
162184

163185
```js
164-
var client = new Client({ keepAlive: true });
186+
var client = new Client({ keepAlive: true })
165187
```
166188

167189
This should help with backends incorrectly considering idle clients to be dead and prematurely disconnecting them.
@@ -173,12 +195,12 @@ This should help with backends incorrectly considering idle clients to be dead a
173195
Example:
174196

175197
```js
176-
var client = new Client();
177-
client.connect();
178-
client.query("SELECT $1::text as name", ["brianc"]).then(function(res) {
179-
console.log("hello from", res.rows[0]);
180-
client.end();
181-
});
198+
var client = new Client()
199+
client.connect()
200+
client.query('SELECT $1::text as name', ['brianc']).then(function (res) {
201+
console.log('hello from', res.rows[0])
202+
client.end()
203+
})
182204
```
183205

184206
### v5.0.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repo is a monorepo which contains the core [pg](https://github.com/brianc/n
1515
- [pg-pool](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool)
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)
18+
- [pg-connection-string](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string)
1819

1920

2021
## Documenation

SPONSORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node-postgres is made possible by the helpful contributors from the community as
77
- [Timescale](https://timescale.com)
88
- [Nafundi](https://nafundi.com)
99
- [CrateDB](https://crate.io/)
10+
- [BitMEX](https://www.bitmex.com/app/trade/XBTUSD)
1011

1112
# Supporters
1213

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test": "yarn lint && yarn lerna exec yarn test",
1414
"build": "yarn lerna exec --scope pg-protocol yarn build",
1515
"pretest": "yarn build",
16-
"lint": "!([[ -e node_modules/.bin/prettier ]]) || eslint '*/**/*.{js,ts,tsx}'"
16+
"lint": "if [ -x ./node_modules/.bin/prettier ]; then eslint '*/**/*.{js,ts,tsx}'; fi;"
1717
},
1818
"devDependencies": {
1919
"@typescript-eslint/eslint-plugin": "^2.27.0",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service_name: travis-pro
2+
repo_token: 5F6dODinz9L9uFR6HatKmtsYDoV1A5S2N
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# Compiled binary addons (http://nodejs.org/api/addons.html)
20+
build/Release
21+
22+
# Dependency directory
23+
# Deployed apps should consider commenting this line out:
24+
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
25+
node_modules
26+
package-lock.json
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
- '6.9'
5+
- '8'
6+
after_success: 'npm run coveralls'

packages/pg-connection-string/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Iced Development
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
pg-connection-string
2+
====================
3+
4+
[![NPM](https://nodei.co/npm/pg-connection-string.png?compact=true)](https://nodei.co/npm/pg-connection-string/)
5+
6+
[![Build Status](https://travis-ci.org/iceddev/pg-connection-string.svg?branch=master)](https://travis-ci.org/iceddev/pg-connection-string)
7+
[![Coverage Status](https://coveralls.io/repos/github/iceddev/pg-connection-string/badge.svg?branch=master)](https://coveralls.io/github/iceddev/pg-connection-string?branch=master)
8+
9+
Functions for dealing with a PostgresSQL connection string
10+
11+
`parse` method taken from [node-postgres](https://github.com/brianc/node-postgres.git)
12+
Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)
13+
MIT License
14+
15+
## Usage
16+
17+
```js
18+
var parse = require('pg-connection-string').parse;
19+
20+
var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
21+
```
22+
23+
The resulting config contains a subset of the following properties:
24+
25+
* `host` - Postgres server hostname or, for UNIX doamain sockets, the socket filename
26+
* `port` - port on which to connect
27+
* `user` - User with which to authenticate to the server
28+
* `password` - Corresponding password
29+
* `database` - Database name within the server
30+
* `client_encoding` - string encoding the client will use
31+
* `ssl`, either a boolean or an object with properties
32+
* `cert`
33+
* `key`
34+
* `ca`
35+
* any other query parameters (for example, `application_name`) are preserved intact.
36+
37+
## Connection Strings
38+
39+
The short summary of acceptable URLs is:
40+
41+
* `socket:<path>?<query>` - UNIX domain socket
42+
* `postgres://<user>:<password>@<host>:<port>/<database>?<query>` - TCP connection
43+
44+
But see below for more details.
45+
46+
### UNIX Domain Sockets
47+
48+
When user and password are not given, the socket path follows `socket:`, as in `socket:/var/run/pgsql`.
49+
This form can be shortened to just a path: `/var/run/pgsql`.
50+
51+
When user and password are given, they are included in the typical URL positions, with an empty `host`, as in `socket://user:pass@/var/run/pgsql`.
52+
53+
Query parameters follow a `?` character, including the following special query parameters:
54+
55+
* `db=<database>` - sets the database name (urlencoded)
56+
* `encoding=<encoding>` - sets the `client_encoding` property
57+
58+
### TCP Connections
59+
60+
TCP connections to the Postgres server are indicated with `pg:` or `postgres:` schemes (in fact, any scheme but `socket:` is accepted).
61+
If username and password are included, they should be urlencoded.
62+
The database name, however, should *not* be urlencoded.
63+
64+
Query parameters follow a `?` character, including the following special query parameters:
65+
* `host=<host>` - sets `host` property, overriding the URL's host
66+
* `encoding=<encoding>` - sets the `client_encoding` property
67+
* `ssl=1`, `ssl=true`, `ssl=0`, `ssl=false` - sets `ssl` to true or false, accordingly
68+
* `sslcert=<filename>` - reads data from the given file and includes the result as `ssl.cert`
69+
* `sslkey=<filename>` - reads data from the given file and includes the result as `ssl.key`
70+
* `sslrootcert=<filename>` - reads data from the given file and includes the result as `ssl.ca`
71+
72+
A bare relative URL, such as `salesdata`, will indicate a database name while leaving other properties empty.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function parse(connectionString: string): ConnectionOptions
2+
3+
export interface ConnectionOptions {
4+
host: string | null
5+
password?: string
6+
user?: string
7+
port?: string | null
8+
database: string | null | undefined
9+
client_encoding?: string
10+
ssl?: boolean | string
11+
12+
application_name?: string
13+
fallback_application_name?: string
14+
}

0 commit comments

Comments
 (0)