Skip to content

Commit ef5aba7

Browse files
committed
fixup! Add support of PostgreSQL 10 features of connection string with multiple hosts
1 parent 04a3fcc commit ef5aba7

File tree

1 file changed

+37
-43
lines changed

1 file changed

+37
-43
lines changed

lib/connection-parameters.js

+37-43
Original file line numberDiff line numberDiff line change
@@ -54,49 +54,43 @@ var ConnectionParameters = function (config) {
5454
// if the config has a connectionString defined, parse IT into the config we use
5555
// this will override other default values with what is stored in connectionString
5656
if (config.connectionString) {
57-
// a unix socket connection string starts from '/' or 'socket:'
58-
if (config.connectionString.indexOf('/') === 0 || config.connectionString.indexOf('socket:') === 0) {
59-
config = Object.assign({ isDomainSocket: true }, config, pgparse(config.connectionString))
60-
// connection uri
61-
} else {
62-
config = Object.assign({}, config, parse(config.connectionString))
63-
64-
// mimicrate connection-string object to postgrsql compatible
65-
// convert path to database name
66-
if (Array.isArray(config.path)) {
67-
config.database = config.path[0]
68-
}
69-
70-
// convert hosts list to host and port
71-
if (Array.isArray(config.hosts)) {
72-
config.host = config.hosts.map(function (host) {
73-
return host.name
74-
})
75-
// take first port in hosts list
76-
config.port = config.hosts[0].port
77-
}
78-
79-
// convert params to separeted options
80-
if (config.params && typeof config.params === 'object') {
81-
Object.keys(config.params).forEach(function (key) {
82-
var val = config.params[key]
83-
84-
switch (val) {
85-
case 'true':
86-
val = true
87-
break
88-
case 'false':
89-
val = false
90-
break
91-
default:
92-
var intVal = parseInt(val)
93-
if (!isNaN(intVal)) {
94-
val = intVal
95-
}
96-
}
97-
config[key] = val
98-
})
99-
}
57+
config = Object.assign({}, config, parse(config.connectionString))
58+
59+
// mimicrate connection-string object to postgrsql compatible
60+
// convert path to database name
61+
if (Array.isArray(config.path)) {
62+
config.database = config.path[0]
63+
}
64+
65+
// convert hosts list to host and port
66+
if (Array.isArray(config.hosts)) {
67+
config.host = config.hosts.map(function (host) {
68+
return host.name
69+
})
70+
// take first port in hosts list
71+
config.port = config.hosts[0].port
72+
}
73+
74+
// convert params to separeted options
75+
if (config.params && typeof config.params === 'object') {
76+
Object.keys(config.params).forEach(function (key) {
77+
var val = config.params[key]
78+
79+
switch (val) {
80+
case 'true':
81+
val = true
82+
break
83+
case 'false':
84+
val = false
85+
break
86+
default:
87+
var intVal = parseInt(val)
88+
if (!isNaN(intVal)) {
89+
val = intVal
90+
}
91+
}
92+
config[key] = val
93+
})
10094
}
10195
}
10296

0 commit comments

Comments
 (0)