From a2bb76f9d0ed557007f3584c75c38782e7e31e74 Mon Sep 17 00:00:00 2001 From: Anton Nesterov Date: Thu, 5 Oct 2023 17:14:55 +0000 Subject: [PATCH] docs: improve example with parsing connection string for pg-pool package, use URL construstor --- packages/pg-pool/README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/pg-pool/README.md b/packages/pg-pool/README.md index b5f20bae9..b5bc582d2 100644 --- a/packages/pg-pool/README.md +++ b/packages/pg-pool/README.md @@ -52,17 +52,16 @@ The Pool constructor does not support passing a Database URL as the parameter. T ```js const Pool = require('pg-pool'); -const url = require('url') -const params = url.parse(process.env.DATABASE_URL); -const auth = params.auth.split(':'); + +const databaseUrl = new URL(process.env.DATABASE_URL); const config = { - user: auth[0], - password: auth[1], - host: params.hostname, - port: params.port, - database: params.pathname.split('/')[1], + user: databaseUrl.username, + password: databaseUrl.password, + host: databaseUrl.searchParams.get('host') || databaseUrl.hostname, + database: databaseUrl.pathname.split('/')[1], + port: databaseUrl.port, ssl: true };