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

The postgres lib cannot parse my url string correctly to connect to my local postgresql #984

Open
janydoe opened this issue Nov 20, 2024 · 0 comments

Comments

@janydoe
Copy link

janydoe commented Nov 20, 2024

I try to set postgresql://user@localhost/db?host=/run/postgresql and postgresql:///db?host=/run/postgresql but seems it doesn't work. You get replace all query parameters here

Specification:
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS

You can use pg-connection-string package

but actually we can use URL to parse it

new URL('postgresql://user:pass@localhost:5432/db?host=/run/postgresql')
URL {
  href: 'postgresql://user:pass@localhost:5432/db?host=/run/postgresql',
  origin: 'null',
  protocol: 'postgresql:',
  username: 'user',
  password: 'pass',
  host: 'localhost:5432',
  hostname: 'localhost',
  port: '5432',
  pathname: '/db',
  search: '?host=/run/postgresql',
  searchParams: URLSearchParams { 'host' => '/run/postgresql' },
  hash: ''
}
new URL('postgresql:///db?host=/run/postgresql')
URL {
  href: 'postgresql:///db?host=/run/postgresql',
  origin: 'null',
  protocol: 'postgresql:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '/db',
  search: '?host=/run/postgresql',
  searchParams: URLSearchParams { 'host' => '/run/postgresql' },
  hash: ''
}
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