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

Add support for connecting to a Postgres database via Unix sockets. #70

Merged
merged 5 commits into from May 31, 2018

Conversation

MrMage
Copy link
Contributor

@MrMage MrMage commented May 27, 2018

Happy to add a connectivity test as well, but I don't know whether the Postgres DB used in CI is set up for supporting Unix sockets. Let me know if you can provide any insights on that.

Motivation: Unix sockets have lower latency and higher throughput than TCP sockets. There are reports that indicate this to be particularly relevant when using Google Cloud SQL proxy.

Copy link
Member

@tanner0101 tanner0101 left a comment

Choose a reason for hiding this comment

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

Looks great, just some gardening comments 👍

extension PostgreSQLConnection {
/// Connects to a Redis server using a TCP socket.
public static func connect(
hostname: String = "localhost",
Copy link
Member

Choose a reason for hiding this comment

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

There needs to be a deprecated method for this old API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added one.

extension PostgreSQLConnection {
/// Connects to a PostgreSQL server using a TCP socket.
public static func connect(
to serverAddress: PostgreSQLDatabaseConfig.ServerAddress = .default,
Copy link
Member

Choose a reason for hiding this comment

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

There appears to be a formatting issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks! Fixed whitespace everywhere.

case unixSocket(path: String)

public static let `default` = ServerAddress.tcp(hostname: "localhost", port: 5432)
public static let defaultViaSocket = ServerAddress.unixSocket(path: "/tmp/.s.PGSQL.5432")
Copy link
Member

Choose a reason for hiding this comment

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

I think socketDefault would be a fine name here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

/// Destination port.
public let port: Int

public enum ServerAddress {
Copy link
Member

Choose a reason for hiding this comment

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

This deserves a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@tanner0101 tanner0101 added the enhancement New feature or request label May 30, 2018
@tanner0101 tanner0101 added this to the 1.0.0 milestone May 30, 2018
@tanner0101 tanner0101 self-assigned this May 30, 2018
@MrMage
Copy link
Contributor Author

MrMage commented May 30, 2018

PTAL

Copy link
Member

@tanner0101 tanner0101 left a comment

Choose a reason for hiding this comment

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

great, thanks!

@tanner0101 tanner0101 merged commit 07fe6bd into master May 31, 2018
@penny-coin
Copy link

Hey @MrMage, you just merged a pull request, have a coin!

You now have 9 coins.

@tanner0101 tanner0101 deleted the unix-sockets branch May 31, 2018 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Vapor 3
  
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

3 participants