MCPcopy Create free account
hub / github.com/denodrivers/postgres / parseOptionsFromUri

Function parseOptionsFromUri

connection/connection_params.ts:310–385  ·  view source on GitHub ↗
(connection_string: string)

Source from the content-addressed store, hash-verified

308}
309
310function parseOptionsFromUri(connection_string: string): ClientOptions {
311 let postgres_uri: PostgresUri;
312 try {
313 const uri = parseConnectionUri(connection_string);
314 postgres_uri = {
315 application_name: uri.params.application_name,
316 dbname: uri.path || uri.params.dbname,
317 driver: uri.driver,
318 host: uri.host || uri.params.host,
319 options: uri.params.options,
320 password: uri.password || uri.params.password,
321 port: uri.port || uri.params.port,
322 // Compatibility with JDBC, not standard
323 // Treat as sslmode=require
324 sslmode: uri.params.ssl === "true"
325 ? "require"
326 : (uri.params.sslmode as TLSModes),
327 user: uri.user || uri.params.user,
328 };
329 } catch (e) {
330 throw new ConnectionParamsError("Could not parse the connection string", e);
331 }
332
333 if (!["postgres", "postgresql"].includes(postgres_uri.driver)) {
334 throw new ConnectionParamsError(
335 `Supplied DSN has invalid driver: ${postgres_uri.driver}.`,
336 );
337 }
338
339 // No host by default means socket connection
340 const host_type = postgres_uri.host
341 ? isAbsolute(postgres_uri.host) ? "socket" : "tcp"
342 : "socket";
343
344 const options = postgres_uri.options
345 ? parseOptionsArgument(postgres_uri.options)
346 : {};
347
348 let tls: TLSOptions | undefined;
349 switch (postgres_uri.sslmode) {
350 case undefined: {
351 break;
352 }
353 case "disable": {
354 tls = { enabled: false, enforce: false, caCertificates: [] };
355 break;
356 }
357 case "prefer": {
358 tls = { enabled: true, enforce: false, caCertificates: [] };
359 break;
360 }
361 case "require":
362 case "verify-ca":
363 case "verify-full": {
364 tls = { enabled: true, enforce: true, caCertificates: [] };
365 break;
366 }
367 default: {

Callers 1

createParamsFunction · 0.85

Calls 2

parseConnectionUriFunction · 0.90
parseOptionsArgumentFunction · 0.85

Tested by

no test coverage detected