File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Sources/PostgreSQL/Database Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change
1
+ import Foundation
1
2
/// Config options for a `PostgreSQLConnection`
2
3
public struct PostgreSQLDatabaseConfig {
3
4
/// Creates a `PostgreSQLDatabaseConfig` with default settings.
@@ -29,4 +30,25 @@ public struct PostgreSQLDatabaseConfig {
29
30
self . database = database
30
31
self . password = password
31
32
}
33
+
34
+ public init ( connectionString: String ) throws {
35
+ guard let url = URL ( string: connectionString) ,
36
+ let hostname = url. host,
37
+ let port = url. port,
38
+ let username = url. user,
39
+ let database = URL ( string: connectionString) ? . path,
40
+ database. count > 0
41
+ else {
42
+ throw PostgreSQLError ( identifier: " Bad Connection String " ,
43
+ reason: " Host could not be parsed " ,
44
+ possibleCauses: [ " Foundation URL is unable to parse the provided connection string " ] ,
45
+ suggestedFixes: [ " Check the connection string being passed " ] ,
46
+ source: . capture( ) )
47
+ }
48
+ self . hostname = hostname
49
+ self . port = port
50
+ self . username = username
51
+ self . database = database
52
+ self . password = url. password
53
+ }
32
54
}
Original file line number Diff line number Diff line change 1
- import Async
2
1
import Foundation
3
2
import XCTest
3
+ import NIO
4
4
import PostgreSQL
5
5
6
6
class PostgreSQLConnectionTests : XCTestCase {
You can’t perform that action at this time.
0 commit comments