Skip to content

feat: Allow localhost connection strings#118

Merged
elliott-with-the-longest-name-on-github merged 5 commits intomainfrom
elliott/fix-localhost-connection-string
May 9, 2023
Merged

feat: Allow localhost connection strings#118
elliott-with-the-longest-name-on-github merged 5 commits intomainfrom
elliott/fix-localhost-connection-string

Conversation

@elliott-with-the-longest-name-on-github
Copy link
Copy Markdown
Collaborator

If a connection string is on localhost, don't check for whether it's pooled or non-pooled. Just allow it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented May 4, 2023

🦋 Changeset detected

Latest commit: d932029

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@vercel/postgres Minor
@vercel/postgres-kysely Minor
vercel-storage-integration-test-suite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github marked this pull request as ready for review May 4, 2023 22:41
Copy link
Copy Markdown
Collaborator

@adriancooney adriancooney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented May 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vercel-storage-next-integration-test-suite ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2023 8:30pm

try {
// This seems silly, but we can use all of the hard work put into URL parsing
// if we just convert `postgresql://` to `https://` and then parse it as a URL.
const withHttpsProtocol = connectionString.startsWith('postgresql://')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work without replacing the protocol before parsing the URL:

> new URL("postgresql://localhost:5432")
URL {
  href: 'postgresql://localhost:5432',
  origin: 'null',
  protocol: 'postgresql:',
  username: '',
  password: '',
  host: 'localhost:5432',
  hostname: 'localhost',
  port: '5432',
  pathname: '',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not in some cases 😢 Try running the tests without it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Actually, this very example doesn't work

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that most browsers don’t follow the WHATWG URL spec when it comes to parsing URLs with unknown protocols (example). Parsing postgresql: connection strings with Node.js should work, though (the tests are all passing). 🤔

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

Successfully merging this pull request may close these issues.

3 participants