Skip to content

Commit 13c4908

Browse files
vkuttypCopilot
andcommitted
feat: add Configuration.checkReachability() and expand Encrypt values
- Add checkReachability(timeout:eventLoopGroup:) on Configuration so the FreeTDS-style pre-connect check works on the config object directly: try await config.checkReachability() let conn = try await MSSQLConnection.connect(configuration: config) (delegates to the existing static MSSQLConnection.checkReachability) - Expand Encrypt connection string parsing to cover all FreeTDS values: strict/require → .require | request/optional → .prefer | off → .disable Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c0d9dde commit 13c4908

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

Sources/MSSQLNio/MSSQLConnection.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ public final class MSSQLConnection: SQLDatabase, @unchecked Sendable {
153153
self.password = get("password", "pwd") ?? ""
154154
self.domain = get("domain")
155155

156-
// Encrypt → tls
156+
// Encrypt → tls (supports: True/False/Disable/Strict/Request/Optional/Mandatory)
157157
if let enc = get("encrypt") {
158158
switch enc.lowercased() {
159-
case "true", "yes", "mandatory": self.tls = .require
160-
case "false", "no", "optional": self.tls = .prefer
161-
case "disable": self.tls = .disable
162-
default: self.tls = .prefer
159+
case "true", "yes", "mandatory", "require", "strict": self.tls = .require
160+
case "false", "no", "optional", "request": self.tls = .prefer
161+
case "disable", "off": self.tls = .disable
162+
default: self.tls = .prefer
163163
}
164164
} else {
165165
self.tls = .prefer
@@ -171,6 +171,22 @@ public final class MSSQLConnection: SQLDatabase, @unchecked Sendable {
171171
self.readOnly = get("applicationintent", "application intent")?
172172
.lowercased() == "readonly"
173173
}
174+
175+
/// Verify the server is reachable at TCP level before attempting a full connection.
176+
///
177+
/// Equivalent to `SQLClient.checkReachability(server:port:)` in SQLClient-Swift.
178+
/// Use this for a fast fail-early check before calling `MSSQLConnection.connect(configuration:)`.
179+
///
180+
/// - Parameter timeout: Maximum seconds to wait for a TCP connection. Default 5.
181+
/// - Throws: `SQLError.connectionError` if the host/port is not reachable.
182+
public func checkReachability(
183+
timeout: TimeInterval = 5,
184+
eventLoopGroup: any EventLoopGroup = MultiThreadedEventLoopGroup.singleton
185+
) async throws {
186+
try await MSSQLConnection.checkReachability(
187+
host: host, port: port, timeout: timeout, eventLoopGroup: eventLoopGroup
188+
)
189+
}
174190
}
175191

176192
// MARK: - Internal state

0 commit comments

Comments
 (0)