forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresConnection+Configuration+Deprecated.swift
95 lines (83 loc) · 3.91 KB
/
PostgresConnection+Configuration+Deprecated.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import NIOCore
extension PostgresConnection.Configuration {
/// Legacy connection parameters structure. Replaced by ``PostgresConnection/Configuration/host`` etc.
@available(*, deprecated, message: "Use `Configuration.host` etc. instead.")
public struct Connection {
/// See ``PostgresConnection/Configuration/host``.
public var host: String
/// See ``PostgresConnection/Configuration/port``.
public var port: Int
/// See ``PostgresConnection/Configuration/Options-swift.struct/requireBackendKeyData``.
public var requireBackendKeyData: Bool = true
/// See ``PostgresConnection/Configuration/Options-swift.struct/connectTimeout``.
public var connectTimeout: TimeAmount = .seconds(10)
/// Create a configuration for connecting to a server.
///
/// - Parameters:
/// - host: The hostname to connect to.
/// - port: The TCP port to connect to (defaults to 5432).
public init(host: String, port: Int = 5432) {
self.host = host
self.port = port
}
}
/// Legacy authentication parameters structure. Replaced by ``PostgresConnection/Configuration/username`` etc.
@available(*, deprecated, message: "Use `Configuration.username` etc. instead.")
public struct Authentication {
/// See ``PostgresConnection/Configuration/username``.
public var username: String
/// See ``PostgresConnection/Configuration/password``.
public var password: String?
/// See ``PostgresConnection/Configuration/database``.
public var database: String?
public init(username: String, database: String?, password: String?) {
self.username = username
self.database = database
self.password = password
}
}
/// Accessor for legacy connection parameters. Replaced by ``PostgresConnection/Configuration/host`` etc.
@available(*, deprecated, message: "Use `Configuration.host` etc. instead.")
public var connection: Connection {
get {
var conn: Connection
switch self.endpointInfo {
case .connectTCP(let host, let port):
conn = .init(host: host, port: port)
case .bindUnixDomainSocket(_), .configureChannel(_):
conn = .init(host: "!invalid!", port: 0) // best we can do, really
}
conn.requireBackendKeyData = self.options.requireBackendKeyData
conn.connectTimeout = self.options.connectTimeout
return conn
}
set {
self.endpointInfo = .connectTCP(host: newValue.host, port: newValue.port)
self.options.connectTimeout = newValue.connectTimeout
self.options.requireBackendKeyData = newValue.requireBackendKeyData
}
}
@available(*, deprecated, message: "Use `Configuration.username` etc. instead.")
public var authentication: Authentication {
get {
.init(username: self.username, database: self.database, password: self.password)
}
set {
self.username = newValue.username
self.password = newValue.password
self.database = newValue.database
}
}
/// Legacy initializer.
/// Replaced by ``PostgresConnection/Configuration/init(host:port:username:password:database:tls:)`` etc.
@available(*, deprecated, message: "Use `init(host:port:username:password:database:tls:)` instead.")
public init(connection: Connection, authentication: Authentication, tls: TLS) {
self.init(
host: connection.host, port: connection.port,
username: authentication.username, password: authentication.password, database: authentication.database,
tls: tls
)
self.options.connectTimeout = connection.connectTimeout
self.options.requireBackendKeyData = connection.requireBackendKeyData
}
}