Skip to content

Commit

Permalink
feat: parse connection URI when using pg.Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Apr 13, 2017
1 parent bf917ba commit a539c33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
};
};

Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type DatabaseConfigurationType = DatabaseConnectionUriType |
export type DatabaseSingleConnectionType = {
end: () => Promise<void>
} & DatabaseConnectionType;

export type DatabasePoolConnectionType = DatabaseConnectionType;

export type DatabaseConnectionType = {
Expand Down

0 comments on commit a539c33

Please sign in to comment.