From c7dc621d3fb52c158eb23aa31dea6bd440700a4a Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 21 Nov 2022 09:57:30 -0800 Subject: [PATCH 001/313] pg-cursor: Fix errors only being sent to half the queue (#2831) * pg-cursor: Add failing test for errors on queued reads * pg-cursor: Fix errors being sent to only half the queue --- packages/pg-cursor/index.js | 4 +++- packages/pg-cursor/test/error-handling.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/pg-cursor/index.js b/packages/pg-cursor/index.js index 9bbda641a..d3c0266b0 100644 --- a/packages/pg-cursor/index.js +++ b/packages/pg-cursor/index.js @@ -171,8 +171,10 @@ class Cursor extends EventEmitter { } // dispatch error to all waiting callbacks for (let i = 0; i < this._queue.length; i++) { - this._queue.pop()[1](msg) + const queuedCallback = this._queue[i][1] + queuedCallback.call(this, msg) } + this._queue.length = 0 if (this.listenerCount('error') > 0) { // only dispatch error events if we have a listener diff --git a/packages/pg-cursor/test/error-handling.js b/packages/pg-cursor/test/error-handling.js index f6edef6d5..22620bd83 100644 --- a/packages/pg-cursor/test/error-handling.js +++ b/packages/pg-cursor/test/error-handling.js @@ -19,6 +19,23 @@ describe('error handling', function () { }) }) }) + + it('errors queued reads', async () => { + const client = new pg.Client() + await client.connect() + + const cursor = client.query(new Cursor('asdfdffsdf')) + + const immediateRead = cursor.read(1) + const queuedRead1 = cursor.read(1) + const queuedRead2 = cursor.read(1) + + assert(await immediateRead.then(() => null, (err) => err)) + assert(await queuedRead1.then(() => null, (err) => err)) + assert(await queuedRead2.then(() => null, (err) => err)) + + client.end() + }) }) describe('read callback does not fire sync', () => { From 12b9a697769b422ad491de3875320665e5a6c61a Mon Sep 17 00:00:00 2001 From: Brian C Date: Wed, 23 Nov 2022 15:08:09 -0600 Subject: [PATCH 002/313] update docs - clean up interface (#2863) * update docs - clean up interface * Remove node v8.x from test matrix --- .github/workflows/ci.yml | 2 +- SPONSORS.md | 2 + docs/pages/apis/client.mdx | 91 ++++++++++++++++++-------------------- docs/pages/apis/pool.mdx | 8 +++- docs/pages/index.mdx | 15 +------ 5 files changed, 53 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e0f098c1..97f4013ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 strategy: matrix: - node: ['8', '10', '12', '14', '16', '18'] + node: ['10', '12', '14', '16', '18'] os: [ubuntu-latest, windows-latest, macos-latest] name: Node.js ${{ matrix.node }} (${{ matrix.os }}) steps: diff --git a/SPONSORS.md b/SPONSORS.md index 3bebb01eb..c16b8d3df 100644 --- a/SPONSORS.md +++ b/SPONSORS.md @@ -16,6 +16,7 @@ node-postgres is made possible by the helpful contributors from the community as - [@BLUE-DEVIL1134](https://github.com/BLUE-DEVIL1134) - [bubble.io](https://bubble.io/) - GitHub[https://github.com/github] +- loveland [https://github.com/loveland] # Supporters @@ -48,3 +49,4 @@ node-postgres is made possible by the helpful contributors from the community as - [Scout APM](https://github.com/scoutapm-sponsorships) - [Sideline Sports](https://github.com/SidelineSports) - [Gadget](https://github.com/gadget-inc) +- [Sentry](https://sentry.io/welcome/) diff --git a/docs/pages/apis/client.mdx b/docs/pages/apis/client.mdx index c983859b6..92268bed8 100644 --- a/docs/pages/apis/client.mdx +++ b/docs/pages/apis/client.mdx @@ -41,8 +41,6 @@ const client = new Client({ ## client.connect -### `client.connect(callback: (err: Error) => void) => void` - Calling `client.connect` with a callback: ```js @@ -57,8 +55,6 @@ client.connect((err) => { }) ``` -### `client.connect() => Promise` - Calling `client.connect` without a callback yields a promise: ```js @@ -74,19 +70,35 @@ _note: connect returning a promise only available in pg@7.0 or above_ ## client.query -### `client.query` - text, optional values, and callback. +### QueryConfig -Passing query text, optional query parameters, and a callback to `client.query` results in a type-signature of: +You can pass an object to `client.query` with the signature of: ```ts -client.query( - text: string, - values?: Array, - callback: (err: Error, result: Result) => void -) => void +type QueryConfig { + // the raw query text + text: string; + + // an array of query parameters + values?: Array; + + // name of the query - used for prepared statements + name?: string; + + // by default rows come out as a key/value pair for each row + // pass the string 'array' here to receive rows as an array of values + rowMode?: string; + + // custom type parsers just for this query result + types?: Types; +} ``` -That is a kinda gross type signature but it translates out to this: +### callback API + +```ts +client.query(text: string, values?: any[], callback?: (err: Error, result: QueryResult) => void) => void +``` **Plain text query with a callback:** @@ -114,15 +126,12 @@ client.query('SELECT $1::text as name', ['brianc'], (err, res) => { }) ``` -### `client.query` - text, optional values: Promise +### Promise API If you call `client.query` with query text and optional parameters but **don't** pass a callback, then you will receive a `Promise` for a query result. ```ts -client.query( - text: string, - values?: Array -) => Promise +client.query(text: string, values?: any[]) => Promise ``` **Plain text query with a promise** @@ -151,30 +160,8 @@ client .then(() => client.end()) ``` -### `client.query(config: QueryConfig, callback: (err?: Error, result?: Result) => void) => void` - -### `client.query(config: QueryConfig) => Promise` - -You can pass an object to `client.query` with the signature of: - ```ts -type QueryConfig { - // the raw query text - text: string; - - // an array of query parameters - values?: Array; - - // name of the query - used for prepared statements - name?: string; - - // by default rows come out as a key/value pair for each row - // pass the string 'array' here to receive rows as an array of values - rowMode?: string; - - // custom type parsers just for this query result - types?: Types; -} +client.query(config: QueryConfig) => Promise ``` **client.query with a QueryConfig and a callback** @@ -246,8 +233,6 @@ query.on('error', (err) => { ## client.end -### client.end(cb?: (err?: Error) => void) => void - Disconnects the client from the PostgreSQL server. ```js @@ -259,8 +244,6 @@ client.end((err) => { }) ``` -### `client.end() => Promise` - Calling end without a callback yields a promise: ```js @@ -274,7 +257,11 @@ _note: end returning a promise is only available in pg7.0 and above_ ## events -### client.on('error', (err: Error) => void) => void +### error + +```ts +client.on('error', (err: Error) => void) => void +``` When the client is in the process of connecting, dispatching a query, or disconnecting it will catch and foward errors from the PostgreSQL server to the respective `client.connect` `client.query` or `client.end` callback/promise; however, the client maintains a long-lived connection to the PostgreSQL back-end and due to network partitions, back-end crashes, fail-overs, etc the client can (and over a long enough time period _will_) eventually be disconnected while it is idle. To handle this you may want to attach an error listener to a client to catch errors. Here's a contrived example: @@ -291,11 +278,15 @@ client.on('error', (err) => { // process output: 'something bad has happened!' followed by stacktrace :P ``` -### client.on('end') => void +### end + +```ts +client.on('end') => void +``` When the client disconnects from the PostgreSQL server it will emit an end event once. -### client.on('notification', (notification: Notification) => void) => void +### notification Used for `listen/notify` events: @@ -321,7 +312,11 @@ client.on('notification', (msg) => { client.query(`NOTIFY foo, 'bar!'`) ``` -### client.on('notice', (notice: Error) => void) => void +### notice + +```ts +client.on('notice', (notice: Error) => void) => void +``` Used to log out [notice messages](https://www.postgresql.org/docs/9.6/static/plpgsql-errors-and-messages.html) from the PostgreSQL server. diff --git a/docs/pages/apis/pool.mdx b/docs/pages/apis/pool.mdx index 6ebc19044..497e5253f 100644 --- a/docs/pages/apis/pool.mdx +++ b/docs/pages/apis/pool.mdx @@ -63,7 +63,9 @@ const pool = new Pool({ Often we only need to run a single query on the database, so as convenience the pool has a method to run a query on the first available idle client and return its result. -`pool.query() => Promise` +```ts +pool.query(text: string, values?: any[]) => Promise +``` ```js const { Pool } = require('pg') @@ -78,7 +80,9 @@ pool Callbacks are also supported: -`pool.query(callback: (err?: Error, result: pg.Result)) => void` +```ts +pool.query(text: string, values?: any[], callback?: (err?: Error, result: pg.Result)) => void +``` ```js const { Pool } = require('pg') diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index 234cf11e1..2e14116b5 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -13,20 +13,7 @@ $ npm install pg ## Supporters -node-postgres continued development and support is made possible by the many [supporters](https://github.com/brianc/node-postgres/blob/master/SPONSORS.md) with a special thanks to our featured supporters: - -
-
- - crate.io - -
-
- - eaze.com - -
-
+node-postgres continued development and support is made possible by the many [supporters](https://github.com/brianc/node-postgres/blob/master/SPONSORS.md). If you or your company would like to sponsor node-postgres stop by [github sponsors](https://github.com/sponsors/brianc) and sign up or feel free to [email me](mailto:brian@pecanware.com) if you want to add your logo to the documentation or discuss higher tiers of sponsorship! From 27d612a2ac2df8737397019a5806f745f19b760e Mon Sep 17 00:00:00 2001 From: Brian C Date: Wed, 23 Nov 2022 21:50:36 -0600 Subject: [PATCH 003/313] Update docs (#2867) - fix config warnings - add search bar - add google analytics --- docs/theme.config.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/theme.config.js b/docs/theme.config.js index 1ec4941ad..4ab2b8d23 100644 --- a/docs/theme.config.js +++ b/docs/theme.config.js @@ -1,16 +1,26 @@ // theme.config.js export default { - projectLink: 'https://github.com/brianc/node-postgres', // GitHub link in the navbar - docsRepositoryBase: 'https://github.com/brianc/node-postgres/blob/master', // base URL for the docs repository + project: { + link: 'https://github.com/brianc/node-postgres', + }, + twitter: { + cardType: 'summary_large_image', + site: 'https://node-postgres.com', + }, + docsRepositoryBase: 'https://github.com/brianc/node-postgres/blob/master/docs', // base URL for the docs repository titleSuffix: ' – node-postgres', - nextLinks: true, - prevLinks: true, - search: true, - customSearch: null, // customizable, you can use algolia for example darkMode: true, footer: true, - footerText: `MIT ${new Date().getFullYear()} © Brian Carlson.`, - footerEditLink: `Edit this page on GitHub`, + navigation: { + prev: true, + next: true, + }, + footer: { + text: `MIT ${new Date().getFullYear()} © Brian Carlson.`, + }, + editLink: { + text: 'Edit this page on GitHub', + }, logo: ( <> ... @@ -22,6 +32,20 @@ export default { + + ), } From 16118cecdd777ff077b70484cb39abf19f5a22f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Dec 2022 22:02:31 -0600 Subject: [PATCH 004/313] Bump eslint-config-prettier from 6.12.0 to 8.5.0 (#2875) Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.12.0 to 8.5.0. - [Release notes](https://github.com/prettier/eslint-config-prettier/releases) - [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-config-prettier/compare/v6.12.0...v8.5.0) --- updated-dependencies: - dependency-name: eslint-config-prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 2dbdaedea..dfd9b0312 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@typescript-eslint/eslint-plugin": "^4.4.0", "@typescript-eslint/parser": "^4.4.0", "eslint": "^7.11.0", - "eslint-config-prettier": "^6.12.0", + "eslint-config-prettier": "^8.5.0", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^3.1.4", "lerna": "^3.19.0", diff --git a/yarn.lock b/yarn.lock index 3a4d75a98..4360e06d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2384,12 +2384,10 @@ escodegen@1.8.x: optionalDependencies: source-map "~0.2.0" -eslint-config-prettier@^6.12.0: - version "6.12.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.12.0.tgz#9eb2bccff727db1c52104f0b49e87ea46605a0d2" - integrity sha512-9jWPlFlgNwRUYVoujvWTQ1aMO8o6648r+K7qU7K5Jmkbyqav1fuEZC0COYpGBxyiAJb65Ra9hrmFx19xRGwXWw== - dependencies: - get-stdin "^6.0.0" +eslint-config-prettier@^8.5.0: + version "8.5.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1" + integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q== eslint-plugin-es@^3.0.0: version "3.0.1" @@ -2927,11 +2925,6 @@ get-stdin@^4.0.1: resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4= -get-stdin@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" - integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== - get-stream@^4.0.0, get-stream@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5" From c6c05f823c6abec337e7ec30db86bba4daababde Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Dec 2022 22:02:45 -0600 Subject: [PATCH 005/313] Bump JSONStream from 0.7.4 to 1.3.5 (#2874) Bumps [JSONStream](https://github.com/dominictarr/JSONStream) from 0.7.4 to 1.3.5. - [Release notes](https://github.com/dominictarr/JSONStream/releases) - [Commits](https://github.com/dominictarr/JSONStream/commits) --- updated-dependencies: - dependency-name: JSONStream dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/pg-query-stream/package.json | 2 +- yarn.lock | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/packages/pg-query-stream/package.json b/packages/pg-query-stream/package.json index 92a42fe95..50f6571f4 100644 --- a/packages/pg-query-stream/package.json +++ b/packages/pg-query-stream/package.json @@ -33,7 +33,7 @@ "@types/mocha": "^8.0.3", "@types/node": "^14.0.0", "@types/pg": "^7.14.5", - "JSONStream": "~0.7.1", + "JSONStream": "~1.3.5", "concat-stream": "~1.0.1", "eslint-plugin-promise": "^6.0.1", "mocha": "^7.1.2", diff --git a/yarn.lock b/yarn.lock index 4360e06d5..2b0959c1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1126,7 +1126,7 @@ mkdirp-promise "^5.0.1" mz "^2.5.0" -JSONStream@^1.0.4, JSONStream@^1.3.4: +JSONStream@^1.0.4, JSONStream@^1.3.4, JSONStream@~1.3.5: version "1.3.5" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" integrity sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ== @@ -1134,14 +1134,6 @@ JSONStream@^1.0.4, JSONStream@^1.3.4: jsonparse "^1.2.0" through ">=2.2.7 <3" -JSONStream@~0.7.1: - version "0.7.4" - resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-0.7.4.tgz#734290e41511eea7c2cfe151fbf9a563a97b9786" - integrity sha1-c0KQ5BUR7qfCz+FR+/mlY6l7l4Y= - dependencies: - jsonparse "0.0.5" - through ">=2.2.7 <3" - abbrev@1: version "1.1.1" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" @@ -3733,11 +3725,6 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" -jsonparse@0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-0.0.5.tgz#330542ad3f0a654665b778f3eb2d9a9fa507ac64" - integrity sha1-MwVCrT8KZUZlt3jz6y2an6UHrGQ= - jsonparse@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" From 3e34816f6fcedb165618367045a3119849ff37cd Mon Sep 17 00:00:00 2001 From: Meron Ogbai <22526062+meronogbai@users.noreply.github.com> Date: Sat, 31 Dec 2022 07:45:42 +0300 Subject: [PATCH 006/313] Update title (#2886) This will change the title of the docs from Next.js Static Site Generator to node-postgres --- docs/theme.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/theme.config.js b/docs/theme.config.js index 4ab2b8d23..263a26945 100644 --- a/docs/theme.config.js +++ b/docs/theme.config.js @@ -24,7 +24,7 @@ export default { logo: ( <> ... - Next.js Static Site Generator + node-postgres ), head: ( From f82f39c20c4a0b834529c7d3d38a43a9ec366572 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Mon, 23 Jan 2023 13:02:39 -0500 Subject: [PATCH 007/313] Add support to stream factory (#2898) This changeset enables declaring the `stream` config value as a factory method. Providing a much more flexible control of the socket connection. Defining a custom `stream` config value allows the postgres driver to support a larger variety of environments/setups such as proxy servers and secure socket connections that are used by cloud providers such as GCP. Currently, usage of the `stream` config value is only viable for single connections given that it's only possible to define a single socket stream instance per new Client/Pool instance. By adding support to a factory function, it becomes possible to enable usage of custom socket streams for connection pools. For reference, see the `mysql2` driver for MySQL (linked below) for prior art example of this pattern. Refs: https://github.com/sidorares/node-mysql2/blob/ba15fe25703665e516ab0a23af8d828d1473b8c3/lib/connection.js#L63-L65 Refs: https://cloud.google.com/sql/docs/postgres/connect-overview Signed-off-by: Ruy Adorno Signed-off-by: Ruy Adorno --- packages/pg/lib/connection.js | 5 +++++ packages/pg/test/unit/connection/startup-tests.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/pg/lib/connection.js b/packages/pg/lib/connection.js index fe04efb6b..86724c5c5 100644 --- a/packages/pg/lib/connection.js +++ b/packages/pg/lib/connection.js @@ -14,7 +14,12 @@ class Connection extends EventEmitter { constructor(config) { super() config = config || {} + this.stream = config.stream || new net.Socket() + if (typeof this.stream === 'function') { + this.stream = this.stream(config) + } + this._keepAlive = config.keepAlive this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis this.lastBuffer = false diff --git a/packages/pg/test/unit/connection/startup-tests.js b/packages/pg/test/unit/connection/startup-tests.js index e2eb6ee99..d5d30d5de 100644 --- a/packages/pg/test/unit/connection/startup-tests.js +++ b/packages/pg/test/unit/connection/startup-tests.js @@ -7,6 +7,18 @@ test('connection can take existing stream', function () { assert.equal(con.stream, stream) }) +test('connection can take stream factory method', function () { + var stream = new MemoryStream() + var connectionOpts = {} + var makeStream = function (opts) { + assert.equal(connectionOpts, opts) + return stream + } + connectionOpts.stream = makeStream + var con = new Connection(connectionOpts) + assert.equal(con.stream, stream) +}) + test('using any stream', function () { var makeStream = function () { var stream = new MemoryStream() From bb8745b2159a5096c25acba23dc0603c0f75fe5e Mon Sep 17 00:00:00 2001 From: Sehrope Sarkuni Date: Mon, 23 Jan 2023 13:03:51 -0500 Subject: [PATCH 008/313] Fix SASL to bubble up errors, enable SASL tests in CI, and add informative empty SASL password message (#2901) * Enable SASL tests in GitHub actions CI * Add SASL test to ensure that client password is a string * Fix SASL error handling to emit and bubble up errors * Add informative error when SASL password is empty string --- .github/workflows/ci.yml | 15 +++++++- packages/pg/lib/client.js | 24 +++++++++--- packages/pg/lib/sasl.js | 3 ++ .../integration/client/sasl-scram-tests.js | 21 ++++++++++ .../pg/test/unit/client/sasl-scram-tests.js | 38 +++++++++++++++++++ 5 files changed, 94 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97f4013ba..ab5bef47b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: ci_db_test + POSTGRES_HOST_AUTH_METHOD: 'md5' ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 @@ -23,7 +24,19 @@ jobs: node: ['10', '12', '14', '16', '18'] os: [ubuntu-latest, windows-latest, macos-latest] name: Node.js ${{ matrix.node }} (${{ matrix.os }}) + env: + PGUSER: postgres + PGHOST: localhost + PGPASSWORD: postgres + PGDATABASE: ci_db_test + PGTESTNOSSL: 'true' + SCRAM_TEST_PGUSER: scram_test + SCRAM_TEST_PGPASSWORD: test4scram steps: + - run: | + psql \ + -c "SET password_encryption = 'scram-sha-256'" \ + -c "CREATE ROLE scram_test LOGIN PASSWORD 'test4scram'" - uses: actions/checkout@v3 with: persist-credentials: false @@ -34,4 +47,4 @@ jobs: cache: yarn - run: yarn install # TODO(bmc): get ssl tests working in ci - - run: PGTESTNOSSL=true PGUSER=postgres PGPASSWORD=postgres PGDATABASE=ci_db_test yarn test + - run: yarn test diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index 82d571d8a..2090c4b5f 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -247,19 +247,31 @@ class Client extends EventEmitter { _handleAuthSASL(msg) { this._checkPgPass(() => { - this.saslSession = sasl.startSession(msg.mechanisms) - this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response) + try { + this.saslSession = sasl.startSession(msg.mechanisms) + this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response) + } catch (err) { + this.connection.emit('error', err) + } }) } _handleAuthSASLContinue(msg) { - sasl.continueSession(this.saslSession, this.password, msg.data) - this.connection.sendSCRAMClientFinalMessage(this.saslSession.response) + try { + sasl.continueSession(this.saslSession, this.password, msg.data) + this.connection.sendSCRAMClientFinalMessage(this.saslSession.response) + } catch (err) { + this.connection.emit('error', err) + } } _handleAuthSASLFinal(msg) { - sasl.finalizeSession(this.saslSession, msg.data) - this.saslSession = null + try { + sasl.finalizeSession(this.saslSession, msg.data) + this.saslSession = null + } catch (err) { + this.connection.emit('error', err) + } } _handleBackendKeyData(msg) { diff --git a/packages/pg/lib/sasl.js b/packages/pg/lib/sasl.js index fb703b270..c8d2d2bdc 100644 --- a/packages/pg/lib/sasl.js +++ b/packages/pg/lib/sasl.js @@ -23,6 +23,9 @@ function continueSession(session, password, serverData) { if (typeof password !== 'string') { throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string') } + if (password === '') { + throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string') + } if (typeof serverData !== 'string') { throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string') } diff --git a/packages/pg/test/integration/client/sasl-scram-tests.js b/packages/pg/test/integration/client/sasl-scram-tests.js index debc28685..3b3fd4a57 100644 --- a/packages/pg/test/integration/client/sasl-scram-tests.js +++ b/packages/pg/test/integration/client/sasl-scram-tests.js @@ -73,3 +73,24 @@ suite.testAsync('sasl/scram fails when password is wrong', async () => { ) assert.ok(usingSasl, 'Should be using SASL for authentication') }) + +suite.testAsync('sasl/scram fails when password is empty', async () => { + const client = new pg.Client({ + ...config, + // We use a password function here so the connection defaults do not + // override the empty string value with one from process.env.PGPASSWORD + password: () => '', + }) + let usingSasl = false + client.connection.once('authenticationSASL', () => { + usingSasl = true + }) + await assert.rejects( + () => client.connect(), + { + message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string', + }, + 'Error code should be for a password error' + ) + assert.ok(usingSasl, 'Should be using SASL for authentication') +}) diff --git a/packages/pg/test/unit/client/sasl-scram-tests.js b/packages/pg/test/unit/client/sasl-scram-tests.js index e53448bdf..36a5556b4 100644 --- a/packages/pg/test/unit/client/sasl-scram-tests.js +++ b/packages/pg/test/unit/client/sasl-scram-tests.js @@ -80,6 +80,44 @@ test('sasl/scram', function () { ) }) + test('fails when client password is not a string', function () { + for(const badPasswordValue of [null, undefined, 123, new Date(), {}]) { + assert.throws( + function () { + sasl.continueSession( + { + message: 'SASLInitialResponse', + clientNonce: 'a', + }, + badPasswordValue, + 'r=1,i=1' + ) + }, + { + message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string', + } + ) + } + }) + + test('fails when client password is an empty string', function () { + assert.throws( + function () { + sasl.continueSession( + { + message: 'SASLInitialResponse', + clientNonce: 'a', + }, + '', + 'r=1,i=1' + ) + }, + { + message: 'SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string', + } + ) + }) + test('fails when iteration is missing in server message', function () { assert.throws( function () { From 47afe5cded70cfaf873b35ae68eca4986102b988 Mon Sep 17 00:00:00 2001 From: Brian C Date: Mon, 23 Jan 2023 13:55:38 -0800 Subject: [PATCH 009/313] Attempt to fix timing test flake on older versions of node in CI (#2902) --- packages/pg-pool/test/lifetime-timeout.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/pg-pool/test/lifetime-timeout.js b/packages/pg-pool/test/lifetime-timeout.js index fddd5ff00..3e690429e 100644 --- a/packages/pg-pool/test/lifetime-timeout.js +++ b/packages/pg-pool/test/lifetime-timeout.js @@ -21,7 +21,7 @@ describe('lifetime timeout', () => { }) it('connection lifetime should expire and remove the client after the client is done working', (done) => { const pool = new Pool({ maxLifetimeSeconds: 1 }) - pool.query('SELECT pg_sleep(1.01)') + pool.query('SELECT pg_sleep(1.4)') pool.on('remove', () => { console.log('expired while busy - on-remove event') expect(pool.expiredCount).to.equal(0) @@ -33,10 +33,11 @@ describe('lifetime timeout', () => { 'can remove expired clients and recreate them', co.wrap(function* () { const pool = new Pool({ maxLifetimeSeconds: 1 }) - let query = pool.query('SELECT pg_sleep(1)') + let query = pool.query('SELECT pg_sleep(1.4)') expect(pool.expiredCount).to.equal(0) expect(pool.totalCount).to.equal(1) yield query + yield new Promise((resolve) => setTimeout(resolve, 100)) expect(pool.expiredCount).to.equal(0) expect(pool.totalCount).to.equal(0) yield pool.query('SELECT NOW()') From 5bdc61a33d4ef25cc12ea36a4199864109551c56 Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Fri, 27 Jan 2023 09:11:05 -0600 Subject: [PATCH 010/313] Remove expired sponsors --- README.md | 15 +-------------- packages/pg/README.md | 13 +------------ 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 15b693128..0cf4c5e37 100644 --- a/README.md +++ b/README.md @@ -55,20 +55,7 @@ You can also follow me [@briancarlson](https://twitter.com/briancarlson) if that ## Sponsorship :two_hearts: -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: - -
-

- - - -

-

- - - -

-
+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). If you or your company are benefiting from node-postgres and would like to help keep the project financially sustainable [please consider supporting](https://github.com/sponsors/brianc) its development. diff --git a/packages/pg/README.md b/packages/pg/README.md index b3158b570..e21f34a06 100644 --- a/packages/pg/README.md +++ b/packages/pg/README.md @@ -46,18 +46,7 @@ You can also follow me [@briancarlson](https://twitter.com/briancarlson) if that ## Sponsorship :two_hearts: -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: - -
- - - - - - - - -
+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). If you or your company are benefiting from node-postgres and would like to help keep the project financially sustainable [please consider supporting](https://github.com/sponsors/brianc) its development. From 20a243e8b30926a348cafc44177e95345618f7bc Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Fri, 27 Jan 2023 09:12:49 -0600 Subject: [PATCH 011/313] Publish - pg-cursor@2.8.0 - pg-protocol@1.6.0 - pg-query-stream@4.3.0 - pg@8.9.0 --- packages/pg-cursor/package.json | 4 ++-- packages/pg-protocol/package.json | 2 +- packages/pg-query-stream/package.json | 6 +++--- packages/pg/package.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/pg-cursor/package.json b/packages/pg-cursor/package.json index c12906abd..5fabf5b28 100644 --- a/packages/pg-cursor/package.json +++ b/packages/pg-cursor/package.json @@ -1,6 +1,6 @@ { "name": "pg-cursor", - "version": "2.7.4", + "version": "2.8.0", "description": "Query cursor extension for node-postgres", "main": "index.js", "directories": { @@ -18,7 +18,7 @@ "license": "MIT", "devDependencies": { "mocha": "^7.1.2", - "pg": "^8.8.0" + "pg": "^8.9.0" }, "peerDependencies": { "pg": "^8" diff --git a/packages/pg-protocol/package.json b/packages/pg-protocol/package.json index ae9ba6f52..ff56dc3be 100644 --- a/packages/pg-protocol/package.json +++ b/packages/pg-protocol/package.json @@ -1,6 +1,6 @@ { "name": "pg-protocol", - "version": "1.5.0", + "version": "1.6.0", "description": "The postgres client/server binary protocol, implemented in TypeScript", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/pg-query-stream/package.json b/packages/pg-query-stream/package.json index 50f6571f4..0c090c4a2 100644 --- a/packages/pg-query-stream/package.json +++ b/packages/pg-query-stream/package.json @@ -1,6 +1,6 @@ { "name": "pg-query-stream", - "version": "4.2.4", + "version": "4.3.0", "description": "Postgres query result returned as readable stream", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -37,7 +37,7 @@ "concat-stream": "~1.0.1", "eslint-plugin-promise": "^6.0.1", "mocha": "^7.1.2", - "pg": "^8.8.0", + "pg": "^8.9.0", "stream-spec": "~0.3.5", "ts-node": "^8.5.4", "typescript": "^4.0.3" @@ -46,6 +46,6 @@ "pg": "^8" }, "dependencies": { - "pg-cursor": "^2.7.4" + "pg-cursor": "^2.8.0" } } diff --git a/packages/pg/package.json b/packages/pg/package.json index 37afe6149..6c0f60a38 100644 --- a/packages/pg/package.json +++ b/packages/pg/package.json @@ -1,6 +1,6 @@ { "name": "pg", - "version": "8.8.0", + "version": "8.9.0", "description": "PostgreSQL client - pure javascript & libpq with the same API", "keywords": [ "database", @@ -24,7 +24,7 @@ "packet-reader": "1.0.0", "pg-connection-string": "^2.5.0", "pg-pool": "^3.5.2", - "pg-protocol": "^1.5.0", + "pg-protocol": "^1.6.0", "pg-types": "^2.1.0", "pgpass": "1.x" }, From adbe86d4a057b942298cab1d19b341c67a94d922 Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Fri, 27 Jan 2023 09:15:30 -0600 Subject: [PATCH 012/313] Update changelog --- CHANGELOG.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f017a3d5a..fff8cdf1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,19 @@ For richer information consult the commit log on github with referenced pull req We do not include break-fix version release in this file. +## pg@8.9.0 + +- Add support for [stream factory](https://github.com/brianc/node-postgres/pull/2898). +- [Better errors](https://github.com/brianc/node-postgres/pull/2901) for SASL authentication. +- [Use native crypto module](https://github.com/brianc/node-postgres/pull/2815) for SASL authentication. + ## pg@8.8.0 -- Bump minimum required version of [native bindings](https://github.com/brianc/node-postgres/pull/2787) -- Catch previously uncatchable errors thrown in [`pool.query`](https://github.com/brianc/node-postgres/pull/2569) -- Prevent the pool from blocking the event loop if all clients are [idle](https://github.com/brianc/node-postgres/pull/2721) (and `allowExitOnIdle` is enabled) -- Support `lock_timeout` in [client config](https://github.com/brianc/node-postgres/pull/2779) -- Fix errors thrown in callbacks from [interfering with cleanup](https://github.com/brianc/node-postgres/pull/2753) +- Bump minimum required version of [native bindings](https://github.com/brianc/node-postgres/pull/2787). +- Catch previously uncatchable errors thrown in [`pool.query`](https://github.com/brianc/node-postgres/pull/2569). +- Prevent the pool from blocking the event loop if all clients are [idle](https://github.com/brianc/node-postgres/pull/2721) (and `allowExitOnIdle` is enabled). +- Support `lock_timeout` in [client config](https://github.com/brianc/node-postgres/pull/2779). +- Fix errors thrown in callbacks from [interfering with cleanup](https://github.com/brianc/node-postgres/pull/2753). ### pg-pool@3.5.0 From 5703791640ba92558f162120f235b29eaf0e4cf0 Mon Sep 17 00:00:00 2001 From: Cody Greene Date: Mon, 6 Mar 2023 10:10:07 -0800 Subject: [PATCH 013/313] fix: double client.end() hang (#2717) * fix: double client.end() hang fixes https://github.com/brianc/node-postgres/issues/2716 `client.end()` will resolve early if the connection is already dead, rather than waiting for an "end" event that will never arrive. * fix: client.end() resolves when socket is fully closed --- packages/pg/lib/client.js | 4 +- packages/pg/lib/connection.js | 3 -- .../test/integration/gh-issues/2716-tests.js | 38 +++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 packages/pg/test/integration/gh-issues/2716-tests.js diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index 2090c4b5f..99c06d661 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -37,6 +37,7 @@ class Client extends EventEmitter { this._Promise = c.Promise || global.Promise this._types = new TypeOverrides(c.types) this._ending = false + this._ended = false this._connecting = false this._connected = false this._connectionError = false @@ -132,6 +133,7 @@ class Client extends EventEmitter { clearTimeout(this.connectionTimeoutHandle) this._errorAllQueries(error) + this._ended = true if (!this._ending) { // if the connection is ended without us calling .end() @@ -603,7 +605,7 @@ class Client extends EventEmitter { this._ending = true // if we have never connected, then end is a noop, callback immediately - if (!this.connection._connecting) { + if (!this.connection._connecting || this._ended) { if (cb) { cb() } else { diff --git a/packages/pg/lib/connection.js b/packages/pg/lib/connection.js index 86724c5c5..9e24391b6 100644 --- a/packages/pg/lib/connection.js +++ b/packages/pg/lib/connection.js @@ -108,9 +108,6 @@ class Connection extends EventEmitter { } attachListeners(stream) { - stream.on('end', () => { - this.emit('end') - }) parse(stream, (msg) => { var eventName = msg.name === 'error' ? 'errorMessage' : msg.name if (this._emitMessage) { diff --git a/packages/pg/test/integration/gh-issues/2716-tests.js b/packages/pg/test/integration/gh-issues/2716-tests.js new file mode 100644 index 000000000..62d0942ba --- /dev/null +++ b/packages/pg/test/integration/gh-issues/2716-tests.js @@ -0,0 +1,38 @@ +'use strict' +const helper = require('../test-helper') + +const suite = new helper.Suite() + +// https://github.com/brianc/node-postgres/issues/2716 +suite.testAsync('client.end() should resolve if already ended', async () => { + const client = new helper.pg.Client() + await client.connect() + + // this should resolve only when the underlying socket is fully closed, both + // the readable part ("end" event) & writable part ("close" event). + + // https://nodejs.org/docs/latest-v16.x/api/net.html#event-end + // > Emitted when the other end of the socket signals the end of + // > transmission, thus ending the readable side of the socket. + + // https://nodejs.org/docs/latest-v16.x/api/net.html#event-close_1 + // > Emitted once the socket is fully closed. + + // here: stream = socket + + await client.end() + // connection.end() + // stream.end() + // ... + // stream emits "end" + // not listening to this event anymore so the promise doesn't resolve yet + // stream emits "close"; no more events will be emitted from the stream + // connection emits "end" + // promise resolved + + // This should now resolve immediately, rather than wait for connection.on('end') + await client.end() + + // this should resolve immediately, rather than waiting forever + await client.end() +}) From 8804e5caaf2194e75d0a7b44f7819dfc809ea317 Mon Sep 17 00:00:00 2001 From: Aram Zegerius Date: Mon, 6 Mar 2023 19:30:37 +0100 Subject: [PATCH 014/313] Fix typo in URL (#2913) --- docs/pages/features/pooling.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/features/pooling.mdx b/docs/pages/features/pooling.mdx index 4719150be..e291080f2 100644 --- a/docs/pages/features/pooling.mdx +++ b/docs/pages/features/pooling.mdx @@ -19,7 +19,7 @@ The easiest and by far most common way to use node-postgres is through a connect ### Good news -node-postgres ships with built-in connection pooling via the [pg-pool](/api/pool) module. +node-postgres ships with built-in connection pooling via the [pg-pool](/apis/pool) module. ## Examples From 810b12558139d0231a71b9bc81206490f2a27ef3 Mon Sep 17 00:00:00 2001 From: "Ryan B. Harvey" Date: Mon, 6 Mar 2023 12:32:13 -0600 Subject: [PATCH 015/313] Emit a 'release' event when a connection is released back to the pool (#2845) --- packages/pg-pool/index.js | 2 ++ packages/pg-pool/test/events.js | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/pg-pool/index.js b/packages/pg-pool/index.js index 00f55b4da..910aee6d2 100644 --- a/packages/pg-pool/index.js +++ b/packages/pg-pool/index.js @@ -330,6 +330,8 @@ class Pool extends EventEmitter { client._poolUseCount = (client._poolUseCount || 0) + 1 + this.emit('release', err, client) + // TODO(bmc): expose a proper, public interface _queryable and _ending if (err || this.ending || !client._queryable || client._ending || client._poolUseCount >= this.options.maxUses) { if (client._poolUseCount >= this.options.maxUses) { diff --git a/packages/pg-pool/test/events.js b/packages/pg-pool/test/events.js index 61979247d..751b14dbc 100644 --- a/packages/pg-pool/test/events.js +++ b/packages/pg-pool/test/events.js @@ -60,6 +60,42 @@ describe('events', function () { }, 100) }) + it('emits release every time a client is released', function (done) { + const pool = new Pool() + let releaseCount = 0 + pool.on('release', function (err, client) { + expect(err instanceof Error).not.to.be(true) + expect(client).to.be.ok() + releaseCount++ + }) + for (let i = 0; i < 10; i++) { + pool.connect(function (err, client, release) { + if (err) return done(err) + release() + }) + pool.query('SELECT now()') + } + setTimeout(function () { + expect(releaseCount).to.be(20) + pool.end(done) + }, 100) + }) + + it('emits release with an error if client is released due to an error', function (done) { + const pool = new Pool() + pool.connect(function (err, client, release) { + expect(err).to.equal(undefined) + const releaseError = new Error('problem') + pool.once('release', function (err, errClient) { + console.log(err, errClient) + expect(err).to.equal(releaseError) + expect(errClient).to.equal(client) + pool.end(done) + }) + release(releaseError) + }) + }) + it('emits error and client if an idle client in the pool hits an error', function (done) { const pool = new Pool() pool.connect(function (err, client) { From ee302cbcf10437e34fd05d70fc003c357b14c654 Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Mon, 6 Mar 2023 14:18:02 -0600 Subject: [PATCH 016/313] Publish - pg-cursor@2.9.0 - pg-pool@3.6.0 - pg-query-stream@4.4.0 - pg@8.10.0 --- packages/pg-cursor/package.json | 4 ++-- packages/pg-pool/package.json | 2 +- packages/pg-query-stream/package.json | 6 +++--- packages/pg/package.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/pg-cursor/package.json b/packages/pg-cursor/package.json index 5fabf5b28..c99c12c29 100644 --- a/packages/pg-cursor/package.json +++ b/packages/pg-cursor/package.json @@ -1,6 +1,6 @@ { "name": "pg-cursor", - "version": "2.8.0", + "version": "2.9.0", "description": "Query cursor extension for node-postgres", "main": "index.js", "directories": { @@ -18,7 +18,7 @@ "license": "MIT", "devDependencies": { "mocha": "^7.1.2", - "pg": "^8.9.0" + "pg": "^8.10.0" }, "peerDependencies": { "pg": "^8" diff --git a/packages/pg-pool/package.json b/packages/pg-pool/package.json index 0bb64b579..38b36708f 100644 --- a/packages/pg-pool/package.json +++ b/packages/pg-pool/package.json @@ -1,6 +1,6 @@ { "name": "pg-pool", - "version": "3.5.2", + "version": "3.6.0", "description": "Connection pool for node-postgres", "main": "index.js", "directories": { diff --git a/packages/pg-query-stream/package.json b/packages/pg-query-stream/package.json index 0c090c4a2..23f5fbd3e 100644 --- a/packages/pg-query-stream/package.json +++ b/packages/pg-query-stream/package.json @@ -1,6 +1,6 @@ { "name": "pg-query-stream", - "version": "4.3.0", + "version": "4.4.0", "description": "Postgres query result returned as readable stream", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -37,7 +37,7 @@ "concat-stream": "~1.0.1", "eslint-plugin-promise": "^6.0.1", "mocha": "^7.1.2", - "pg": "^8.9.0", + "pg": "^8.10.0", "stream-spec": "~0.3.5", "ts-node": "^8.5.4", "typescript": "^4.0.3" @@ -46,6 +46,6 @@ "pg": "^8" }, "dependencies": { - "pg-cursor": "^2.8.0" + "pg-cursor": "^2.9.0" } } diff --git a/packages/pg/package.json b/packages/pg/package.json index 6c0f60a38..6e62a04ea 100644 --- a/packages/pg/package.json +++ b/packages/pg/package.json @@ -1,6 +1,6 @@ { "name": "pg", - "version": "8.9.0", + "version": "8.10.0", "description": "PostgreSQL client - pure javascript & libpq with the same API", "keywords": [ "database", @@ -23,7 +23,7 @@ "buffer-writer": "2.0.0", "packet-reader": "1.0.0", "pg-connection-string": "^2.5.0", - "pg-pool": "^3.5.2", + "pg-pool": "^3.6.0", "pg-protocol": "^1.6.0", "pg-types": "^2.1.0", "pgpass": "1.x" From 661f870e1c741a1dd712f5ad7631aa34419b2af9 Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Mon, 6 Mar 2023 15:48:08 -0600 Subject: [PATCH 017/313] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fff8cdf1c..bf05426e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ For richer information consult the commit log on github with referenced pull req We do not include break-fix version release in this file. +## pg-pool@8.10.0 + +- Emit `release` event when client is returned to [the pool](https://github.com/brianc/node-postgres/pull/2845). + ## pg@8.9.0 - Add support for [stream factory](https://github.com/brianc/node-postgres/pull/2898). From 0f76fb3bb70f0cee118d873aeee4283b32f7217f Mon Sep 17 00:00:00 2001 From: Brian C Date: Tue, 7 Mar 2023 13:55:22 -0600 Subject: [PATCH 018/313] Update path to documentation in readme (#2925) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cf4c5e37..967431358 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Each package in this repo should have its own readme more focused on how to deve ### :star: [Documentation](https://node-postgres.com) :star: -The source repo for the documentation is https://github.com/brianc/node-postgres-docs. +The source repo for the documentation is available for contribution [here](https://github.com/brianc/node-postgres/tree/master/docs). ### Features From 65ca2458fd0079f36a99a7752a7931483cd57ed6 Mon Sep 17 00:00:00 2001 From: "Ryan B. Harvey" Date: Thu, 16 Mar 2023 11:34:50 -0500 Subject: [PATCH 019/313] Add release event to Pool API docs (#2928) --- docs/pages/apis/pool.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/pages/apis/pool.mdx b/docs/pages/apis/pool.mdx index 497e5253f..6323f2e2d 100644 --- a/docs/pages/apis/pool.mdx +++ b/docs/pages/apis/pool.mdx @@ -271,6 +271,12 @@ The error listener is passed the error as the first argument and the client upon uncaught error and potentially crash your node process. +### release + +`pool.on('release', (err: Error, client: Client) => void) => void` + +Whenever a client is released back into the pool, the pool will emit the `release` event. + ### remove `pool.on('remove', (client: Client) => void) => void` From 92351b5f3ea7d76183e92d9a1461987fd826f60f Mon Sep 17 00:00:00 2001 From: Samuel Durante <44513615+samueldurantes@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:49:28 -0300 Subject: [PATCH 020/313] docs(client): improve the Client instance example (#2935) --- docs/pages/apis/client.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/apis/client.mdx b/docs/pages/apis/client.mdx index 92268bed8..d5f335240 100644 --- a/docs/pages/apis/client.mdx +++ b/docs/pages/apis/client.mdx @@ -34,6 +34,7 @@ const { Client } = require('pg') const client = new Client({ host: 'my.database-server.com', port: 5334, + database: 'database-name', user: 'database-user', password: 'secretpassword!!', }) From 48f4398fa75247f4ed8e2470372d0b77712f73e3 Mon Sep 17 00:00:00 2001 From: Brian C Date: Thu, 30 Mar 2023 11:25:35 -0500 Subject: [PATCH 021/313] Update README.md (#2944) Update href to docs --- packages/pg-cursor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pg-cursor/README.md b/packages/pg-cursor/README.md index 1b01b3d83..a3fdf4d00 100644 --- a/packages/pg-cursor/README.md +++ b/packages/pg-cursor/README.md @@ -10,7 +10,7 @@ $ npm install pg-cursor ``` ___note___: this depends on _either_ `npm install pg` or `npm install pg.js`, but you __must__ be using the pure JavaScript client. This will __not work__ with the native bindings. -### :star: [Documentation](https://node-postgres.com/api/cursor) :star: +### :star: [Documentation](https://node-postgres.com/apis/cursor) :star: ### license From b357e1884ad25b23a4ab034b443ddfc8c8261951 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Thu, 20 Apr 2023 16:03:59 +0200 Subject: [PATCH 022/313] fix(theme.config.js): Replace default meta description and social title (#2952) Currently still nextra default. Those are shown in Slack and other social apps when sharing the website. --- docs/theme.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/theme.config.js b/docs/theme.config.js index 263a26945..00410f791 100644 --- a/docs/theme.config.js +++ b/docs/theme.config.js @@ -30,8 +30,8 @@ export default { head: ( <> - - + +