File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Sources/PostgreSQL/Database Expand file tree Collapse file tree 2 files changed +24
-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,26 @@ public struct PostgreSQLDatabaseConfig {
29
30
self . database = database
30
31
self . password = password
31
32
}
33
+
34
+ /// Creates a `PostgreSQLDatabaseConfig` frome a connection string.
35
+ public init ( url: String ) throws {
36
+ guard let urL = URL ( string: url) ,
37
+ let hostname = urL. host,
38
+ let port = urL. port,
39
+ let username = urL. user,
40
+ let database = URL ( string: url) ? . path,
41
+ database. count > 0
42
+ else {
43
+ throw PostgreSQLError ( identifier: " Bad Connection String " ,
44
+ reason: " Host could not be parsed " ,
45
+ possibleCauses: [ " Foundation URL is unable to parse the provided connection string " ] ,
46
+ suggestedFixes: [ " Check the connection string being passed " ] ,
47
+ source: . capture( ) )
48
+ }
49
+ self . hostname = hostname
50
+ self . port = port
51
+ self . username = username
52
+ self . database = database
53
+ self . password = urL. password
54
+ }
32
55
}
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
import Core
6
6
You can’t perform that action at this time.
0 commit comments