porsager / porsager/postgres

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

Open
#984 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

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: ''
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the query-parameter handling in src/index.js around line 540, then compare it with the PostgreSQL URI specification and the provided URL examples. Ensure connection strings using host query parameters, including Unix socket paths, are parsed correctly; the issue does not mention a specific test file.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.