From a539c33aa3bd8e0298f19fcbc81b69eba02682ee Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Thu, 13 Apr 2017 10:44:41 +0100 Subject: [PATCH] feat: parse connection URI when using pg.Pool Fixes https://github.com/brianc/node-postgres/issues/1263 --- package.json | 1 + src/index.js | 8 +++++--- src/types.js | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3a6bf67c..66690263 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "debug": "^2.6.3", "es6-error": "^4.0.2", "pg": "^6.1.5", + "pg-connection-string": "^0.1.3", "pretty-hrtime": "^1.0.3" }, "description": "A PostgreSQL client with strict types and assertions.", diff --git a/src/index.js b/src/index.js index efdf4b5e..896e432b 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,9 @@ import pg, { types } from 'pg'; +import { + parse as parseConnectionString +} from 'pg-connection-string'; import createDebug from 'debug'; import prettyHrtime from 'pretty-hrtime'; import { @@ -144,15 +147,14 @@ const createConnection = async (configuration: DatabaseConfigurationType): Promi }; const createPool = (configuration: DatabaseConfigurationType): DatabasePoolConnectionType => { - const pool = new pg.Pool(configuration); + const pool = new pg.Pool(typeof configuration === 'string' ? parseConnectionString(configuration) : configuration); return { any: any.bind(null, pool), insert: insert.bind(null, pool), many: many.bind(null, pool), one: one.bind(null, pool), - query: query.bind(null, pool), - release: pool.release.bind(pool) + query: query.bind(null, pool) }; }; diff --git a/src/types.js b/src/types.js index eb524825..700fdf27 100644 --- a/src/types.js +++ b/src/types.js @@ -21,6 +21,7 @@ export type DatabaseConfigurationType = DatabaseConnectionUriType | export type DatabaseSingleConnectionType = { end: () => Promise } & DatabaseConnectionType; + export type DatabasePoolConnectionType = DatabaseConnectionType; export type DatabaseConnectionType = {