@@ -18,47 +18,7 @@ var val = function(key, config, envVar) {
18
18
} ;
19
19
20
20
//parses a connection string
21
- var parse = function ( str ) {
22
- var config ;
23
- //unix socket
24
- if ( str . charAt ( 0 ) === '/' ) {
25
- config = str . split ( ' ' ) ;
26
- return { host : config [ 0 ] , database : config [ 1 ] } ;
27
- }
28
- // url parse expects spaces encoded as %20
29
- if ( / | % [ ^ a - f 0 - 9 ] | % [ a - f 0 - 9 ] [ ^ a - f 0 - 9 ] / i. test ( str ) ) {
30
- str = encodeURI ( str ) . replace ( / \% 2 5 ( \d \d ) / g, "%$1" ) ;
31
- }
32
- var result = url . parse ( str , true ) ;
33
- config = { } ;
34
-
35
- if ( result . query . application_name ) {
36
- config . application_name = result . query . application_name ;
37
- }
38
- if ( result . query . fallback_application_name ) {
39
- config . fallback_application_name = result . query . fallback_application_name ;
40
- }
41
-
42
- config . port = result . port ;
43
- if ( result . protocol == 'socket:' ) {
44
- config . host = decodeURI ( result . pathname ) ;
45
- config . database = result . query . db ;
46
- config . client_encoding = result . query . encoding ;
47
- return config ;
48
- }
49
- config . host = result . hostname ;
50
- config . database = result . pathname ? decodeURI ( result . pathname . slice ( 1 ) ) : null ;
51
- var auth = ( result . auth || ':' ) . split ( ':' ) ;
52
- config . user = auth [ 0 ] ;
53
- config . password = auth [ 1 ] ;
54
-
55
- var ssl = result . query . ssl ;
56
- if ( ssl === 'true' || ssl === '1' ) {
57
- config . ssl = true ;
58
- }
59
-
60
- return config ;
61
- } ;
21
+ var parse = require ( 'pg-connection-string' ) . parse ;
62
22
63
23
var useSsl = function ( ) {
64
24
switch ( process . env . PGSSLMODE ) {
0 commit comments