MCPcopy
hub / github.com/brianc/node-postgres / toClientConfig

Function toClientConfig

packages/pg-connection-string/index.js:179–212  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

177
178// convert pg-connection-string config to a ClientConfig
179function toClientConfig(config) {
180 const poolConfig = Object.entries(config).reduce((c, [key, value]) => {
181 if (key === 'ssl') {
182 const sslConfig = value
183
184 if (typeof sslConfig === 'boolean') {
185 c[key] = sslConfig
186 }
187
188 if (typeof sslConfig === 'object') {
189 c[key] = toConnectionOptions(sslConfig)
190 }
191 } else if (value !== undefined && value !== null) {
192 if (key === 'port') {
193 // when port is not specified, it is converted into an empty string
194 // we want to avoid NaN or empty string as a values in ClientConfig
195 if (value !== '') {
196 const v = parseInt(value, 10)
197 if (isNaN(v)) {
198 throw new Error(`Invalid ${key}: ${value}`)
199 }
200
201 c[key] = v
202 }
203 } else {
204 c[key] = value
205 }
206 }
207
208 return c
209 }, Object.create(null))
210
211 return poolConfig
212}
213
214// parses a connection string into ClientConfig
215function parseIntoClientConfig(str) {

Callers 2

parseIntoClientConfigFunction · 0.85
clientConfig.tsFile · 0.85

Calls 1

toConnectionOptionsFunction · 0.85

Tested by

no test coverage detected