File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,11 @@ public struct PostgresConfiguration {
10
10
/// Optional `search_path` to set on new connections.
11
11
public var searchPath : [ String ] ?
12
12
13
- internal var _hostname : String ?
13
+ /// IANA-assigned port number for PostgreSQL
14
+ /// `UInt16(getservbyname("postgresql", "tcp").pointee.s_port).byteSwapped`
15
+ public static var ianaPortNumber : Int { 5432 }
14
16
17
+ internal var _hostname : String ?
15
18
16
19
public init ? ( url: String ) {
17
20
guard let url = URL ( string: url) else {
@@ -31,7 +34,7 @@ public struct PostgresConfiguration {
31
34
guard let hostname = url. host else {
32
35
return nil
33
36
}
34
- let port = url. port ?? 5432
37
+ let port = url. port ?? Self . ianaPortNumber
35
38
36
39
let tlsConfiguration : TLSConfiguration ?
37
40
if url. query? . contains ( " ssl=true " ) == true || url. query? . contains ( " sslmode=require " ) == true {
@@ -68,7 +71,7 @@ public struct PostgresConfiguration {
68
71
69
72
public init (
70
73
hostname: String ,
71
- port: Int = 5432 ,
74
+ port: Int = Self . ianaPortNumber ,
72
75
username: String ,
73
76
password: String ? = nil ,
74
77
database: String ? = nil ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ extension PostgresConnection {
4
4
static func test( on eventLoop: EventLoop ) -> EventLoopFuture < PostgresConnection > {
5
5
do {
6
6
let address : SocketAddress
7
- address = try . makeAddressResolvingHost( hostname, port: 5432 )
7
+ address = try . makeAddressResolvingHost( hostname, port: PostgresConfiguration . ianaPortNumber )
8
8
return connect ( to: address, on: eventLoop) . flatMap { conn in
9
9
return conn. authenticate (
10
10
username: " vapor_username " ,
@@ -22,7 +22,7 @@ extension PostgresConfiguration {
22
22
static var test : Self {
23
23
. init(
24
24
hostname: hostname,
25
- port: 5432 ,
25
+ port: Self . ianaPortNumber ,
26
26
username: " vapor_username " ,
27
27
password: " vapor_password " ,
28
28
database: " vapor_database "
You can’t perform that action at this time.
0 commit comments