Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow all config options when using connection string and object #3327

Open
satire-foxfire opened this issue Oct 9, 2024 · 0 comments

Comments

@satire-foxfire
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant