brianc / node-postgres

PostgreSQL client for node.js.

Home Page:https://node-postgres.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pg-connection-string parser does not work on the browser

tmadeira opened this issue · comments

f305419 made it possible to import and use pg-connection-string on the browser; however, the parser does not work correctly.

On the browser, parse("postgres://user:pass@host:123/base") is currently returning {user: '', password: '', host: '', port: '', database: '/user:pass@host:123/base'}.

That is happening because of the difference between the URL constructor on node vs. browser. At least on Chrome (I'm on Chromium 120.0.6099.217, to be specific), new URL("postgres://user:pass@host:123/base") is not properly parsed:

2024-01-12_14:41:09

The failure happens because it seems to only support some specific protocols -- if I replace postgresql with ftp, I get the correctly parsing:

2024-01-12_14:42:06

What will you use pg-connection-string for on the browser?

What will you use pg-connection-string for on the browser?

@charmander, we currently use it to parse a connection string in the UI of an app/website builder (https://plasmic.app/).

Code (with a workaround replacing [protocol]:// with ftp:// to work on the browser): https://github.com/plasmicapp/plasmic/blob/dff591aa037cb1f20fde216df9c6b4a55d2f5883/platform/wab/src/wab/client/components/modals/DataSourceModal.tsx#L866

Video demonstrating usage:
https://github.com/brianc/node-postgres/assets/3820/508eeff8-659f-474b-b3fc-b0ed97de7f8f