Description
I don't believe there is a way to do this currently, so I believe this would fall more into a feature request than a question, but let me know if there is a way to do this with the current functionality.
Currently you can use both a connection string while still specifying some options like ssl
, but other options like user
or password
don't appear to get merged (they're ignored) unless they're explicitly part of the connection string.
Works:
const connectionString = 'postgres://user:password@hostname:port/database';
const client = new pg.Client({
connectionString,
ssl: true,
});
Doesn't work:
const connectionString = 'postgres://hostname:port/database';
const client = new pg.Client({
connectionString,
user: 'user',
password: 'password',
ssl: true,
});
The alternative I have right now is preparsing the connection string into an instance of URL
first, then manually setting url.user = 'user'
and url.password = 'password'
, and then stringifying it before passing it into the client:
const connectionString = 'postgres://hostname:port/database';
const url = new URL(connectionString);
url.user = 'user';
url.password = 'password';
const client = new pg.Client({
connectionString: String(connectionString),
ssl: true,
});
It'd be really nice for all the properties to "just work", while keeping the same behavior that anything defined in the connection string directly will take precedence.