Render a database URL for printing from the parse node-postgres dials —
new URL, with pg-connection-string's precedence, where a user, host, or
port query parameter overrides the URL's own — so the line names the server
dialed and no credential can leak however the input spells it.
A postgres:// or postgresql:// URL renders as
postgres://[user@]host:port[/dbname]: never the password, and never the
query or fragment (sslmode and the like are dropped by design). The scheme
always prints as postgres://. The port always prints, 5432 when the URL
names none. The user and database name print percent-encoded with
encodeURIComponent, so no control character, escape sequence, or bidi
override reaches the terminal and an @ can't pose as the separator; each
prints only when non-empty. An IP-literal host prints canonically (IPv6
bracketed); a Unix-socket directory prints with each / as %2F. A PGlite
file:// or memory:// URL prints as scheme, host, and path.
The whole line is (not a URL; hidden) for any other scheme, when new URL
rejects the input, when it holds a malformed percent-escape (%ZZ), when
there is no host, when the host is neither an IP literal, a hostname of
A-Z a-z 0-9 . _ -, nor a socket directory of those characters and /, when
the user holds ?, =, &, /, or #, or when the port isn't a number up
to 65535. The host and user rules match the Rust twin's, where they catch
tokio-postgres's split at the first @.
Twin of the Rust fuz_db CLI's display_db_url, byte-identical on the URLs
both drivers read alike. They part where the drivers do: a host= or port=
query parameter overrides the URL's here (tokio-postgres appends it to a list
whose first entry the pool dials); a dbname= query parameter, which
tokio-postgres honours and node-postgres ignores, and a #… fragment, which
tokio-postgres keeps as part of the database name; tokio-postgres also
accepts key=value strings, host lists, and an unencoded / or ? in the
password (here, the placeholder); an unencoded @ in the userinfo splits at
the last @ here, rendering the user and host node-postgres dials, where the
Rust twin prints the placeholder; node-postgres decodes the database name
with decodeURI, so a reserved-character escape such as %2F stays literal
and prints as %252F; an IPv4-mapped IPv6 address serializes differently;
and tokio-postgres refuses an unknown query parameter (sslpassword=) that
node-postgres passes.