Skip to content

Commit 80ddc3c

Browse files
committed
test FluentPostgreSQL gm
1 parent 8e5b40d commit 80ddc3c

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

Sources/PostgreSQL/Database/PostgreSQLDatabaseConfig.swift

+15-23
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,26 @@ public struct PostgreSQLDatabaseConfig {
2828
public init(hostname: String, port: Int = 5432, username: String, database: String? = nil, password: String? = nil, transport: PostgreSQLConnection.TransportConfig = .cleartext) {
2929
self.init(serverAddress: .tcp(hostname: hostname, port: port), username: username, database: database, password: password, transport: transport)
3030
}
31-
32-
public init(serverAddress: PostgreSQLConnection.ServerAddress, username: String, database: String? = nil, password: String? = nil, transport: PostgreSQLConnection.TransportConfig = .cleartext) {
33-
self.username = username
34-
self.database = database
31+
32+
public init(serverAddress: PostgreSQLConnection.ServerAddress, username: String, database: String? = nil, password: String? = nil, transport: PostgreSQLConnection.TransportConfig = .cleartext) {
33+
self.username = username
34+
self.database = database
3535
self.password = password
3636
self.serverAddress = serverAddress
3737
self.transportConfig = transport
3838
}
3939

40-
public init(url urlString: String, transport: PostgreSQLConnection.TransportConfig = .cleartext) throws {
41-
guard let url = URL(string: urlString),
42-
let hostname = url.host,
43-
let port = url.port,
44-
let username = url.user,
45-
let database = url.databaseName,
46-
url.path.count > 0
47-
else {
48-
throw PostgreSQLError(
49-
identifier: "Bad Connection String",
50-
reason: "Host could not be parsed",
51-
possibleCauses: ["Foundation URL is unable to parse the provided connection string"],
52-
suggestedFixes: ["Check the connection string being passed"]
53-
)
40+
public init?(url urlString: String, transport: PostgreSQLConnection.TransportConfig = .cleartext) throws {
41+
guard let url = URL(string: urlString) else {
42+
return nil
5443
}
55-
self.serverAddress = .tcp(hostname: hostname, port: port)
56-
self.username = username
57-
self.database = database
58-
self.password = url.password
59-
self.transportConfig = transport
44+
self.init(
45+
hostname: url.host ?? "localhost",
46+
port: url.port ?? 5432,
47+
username: url.user ?? "vapor",
48+
database: url.databaseName,
49+
password: url.password,
50+
transport: transport
51+
)
6052
}
6153
}

Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class PostgreSQLConnectionTests: XCTestCase {
217217

218218
func testURLParsing() throws {
219219
let databaseURL = "postgres://username:password@localhost:5432/database"
220-
let config = try PostgreSQLDatabaseConfig(url: databaseURL)
220+
let config = try PostgreSQLDatabaseConfig(url: databaseURL)!
221221
XCTAssertEqual("\(config.serverAddress)", "ServerAddress(storage: PostgreSQL.PostgreSQLConnection.ServerAddress.Storage.tcp(hostname: \"localhost\", port: 5432))")
222222
XCTAssertEqual(config.username, "username")
223223
XCTAssertEqual(config.password, "password")

circle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
steps:
5656
- run:
5757
name: Clone Fluent PostgreSQL
58-
command: git clone -b master https://github.com/vapor/fluent-postgresql.git
58+
command: git clone -b gm https://github.com/vapor/fluent-postgresql.git
5959
working_directory: ~/
6060
- run:
6161
name: Switch Fluent PostgreSQL to this PostgreSQL revision
@@ -86,4 +86,4 @@ workflows:
8686
jobs:
8787
- linux
8888
# - macos
89-
89+

0 commit comments

Comments
 (0)