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

fix: postgresql connection URL can use an UNIX Socket #6042

Merged
merged 1 commit into from
Oct 7, 2020

Conversation

paeolo
Copy link
Contributor

@paeolo paeolo commented May 10, 2020

Solves #2614.

  • Current behavior:
    Users may provide an URL in the connection options which is parsed by a generic function to fill the following fields: host, port, username, password, database.
  • Issue:
    You can't give an UNIX socket as host with PostgreSQL.
  • Corrected behavior:
    Provide a ConnectionUrlParser class with different parser functions. The default parser function is left unchanged to prevent any regression with other database types. Concerning PostgreSQL a new function is provided which solves the issue. To prevent any regression, I tested myself the function with multiples strings against the default parser.
  • Exemple of tested strings
    postgres://user:password@host:5432/database (standard)
    postgres://user:password@/var/run/postgresql?dbname=database (UNIX socket)
    postgres:///var/run/postgresql?dbname=database (without username)

@pleerock
Copy link
Member

Thanks for contribution.

You probably don't have to use DriverUtils at all. Just create a local function in postgres driver - that's it. DriverUtils was created for common usage, if some driver have its own logic, better if it won't use DriverUtils at all and use its own implementation.

Also, few other notes:

  • is there some popular package that is able to perform URL parsing? (to prevent extra maintainable code in the codebase). If no, that's fine.
  • can we have a tests for this feature?

@paeolo
Copy link
Contributor Author

paeolo commented May 16, 2020

You're welcome!

@pleerock
Copy link
Member

I would like to prevent extra dependencies, because people who use mysql don't need pg-connection-string. I checked, it looks like pg-connection-string is installed when you install pg itself, and since this code is running only when pg is used, maybe we can just add a check if pg-connection-string and use it? (dynamic require). If nothing was found - throw an exception (not possible case I guess)

@paeolo
Copy link
Contributor Author

paeolo commented May 16, 2020

That's fine for me. I don't have time to do it this week-end but I can do it next week;)
Paul.

@paeolo
Copy link
Contributor Author

paeolo commented Jun 17, 2020

@pleerock Seems better now.
Paul.

@paeolo paeolo reopened this Jun 17, 2020
@guillenotfound
Copy link

Any update on this? 😄

@paeolo
Copy link
Contributor Author

paeolo commented Sep 14, 2020

Any update on this?

It's ready for merge, waiting for @pleerock to review it.

src/driver/postgres/PostgresDriver.ts Outdated Show resolved Hide resolved
src/driver/postgres/PostgresDriver.ts Outdated Show resolved Hide resolved
@guillenotfound
Copy link

I used what's described here and was able to connect from cloud run: #2614 (comment)

@@ -922,11 +921,12 @@ export class PostgresDriver implements Driver {
*/
protected async createPool(options: PostgresConnectionOptions, credentials: PostgresConnectionCredentialsOptions): Promise<any> {

credentials = Object.assign({}, credentials, DriverUtils.buildDriverOptions(credentials)); // todo: do it better way
Copy link
Contributor

Choose a reason for hiding this comment

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

Dropping this line drops something specifically for Oracle & the URL parsing which we don't want anyway.

Sounds good to me!

@imnotjames imnotjames merged commit 21c4166 into typeorm:master Oct 7, 2020
@imnotjames
Copy link
Contributor

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted label hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants