Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c7e3976

Browse files
authored
Update PostgresError's DatabaseError conformance for new PostgresNIO behavior (#208)
Update PostgresError's DatabaseError conformance for new PostgresNIO behavior. Fixes broken tests.
1 parent c7cd020 commit c7e3976

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

β€ŽSources/FluentPostgresDriver/PostgresError+Database.swift

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import FluentSQL
33
import PostgresKit
44
import PostgresNIO
55

6-
extension PostgresError:DatabaseError {
7-
publicvar isSyntaxError: Bool {
8-
switch self.code {
6+
fileprivateextension PostgresError.Code {
7+
var isSyntaxError: Bool {
8+
switch self {
99
case .syntaxErrorOrAccessRuleViolation,
1010
.syntaxError,
1111
.insufficientPrivilege,
@@ -54,18 +54,9 @@ extension PostgresError: DatabaseError {
5454
return false
5555
}
5656
}
57-
58-
publicvar isConnectionClosed: Bool {
57+
58+
var isConstraintFailure: Bool {
5959
switch self {
60-
case .connectionClosed:
61-
return true
62-
default:
63-
return false
64-
}
65-
}
66-
67-
public var isConstraintFailure: Bool {
68-
switch self.code {
6960
case .integrityConstraintViolation,
7061
.restrictViolation,
7162
.notNullViolation,
@@ -79,3 +70,37 @@ extension PostgresError: DatabaseError {
7970
}
8071
}
8172
}
73+
74+
extension PostgresError: DatabaseError {
75+
public var isSyntaxError: Bool { self.code.isSyntaxError }
76+
public var isConnectionClosed: Bool {
77+
switch self {
78+
case .connectionClosed: return true
79+
default: return false
80+
}
81+
}
82+
public var isConstraintFailure: Bool { self.code.isConstraintFailure }
83+
}
84+
85+
extension PSQLError: DatabaseError {
86+
public var isSyntaxError: Bool {
87+
switch self.code {
88+
case .server: return self.serverInfo?[.sqlState].map { PostgresError.Code(raw: 0ドル).isSyntaxError } ?? false
89+
default: return false
90+
}
91+
}
92+
93+
public var isConnectionClosed: Bool {
94+
switch self.code {
95+
case .connectionClosed: return true
96+
default: return false
97+
}
98+
}
99+
100+
public var isConstraintFailure: Bool {
101+
switch self.code {
102+
case .server: return self.serverInfo?[.sqlState].map { PostgresError.Code(raw: 0ドル).isConstraintFailure } ?? false
103+
default: return false
104+
}
105+
}
106+
}

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /