@@ -3,9 +3,9 @@ import FluentSQL
3
3
import PostgresKit
4
4
import PostgresNIO
5
5
6
- extension PostgresError : DatabaseError {
7
- public var isSyntaxError : Bool {
8
- switch self . code {
6
+ fileprivate extension PostgresError . Code {
7
+ var isSyntaxError : Bool {
8
+ switch self {
9
9
case . syntaxErrorOrAccessRuleViolation,
10
10
. syntaxError,
11
11
. insufficientPrivilege,
@@ -54,18 +54,9 @@ extension PostgresError: DatabaseError {
54
54
return false
55
55
}
56
56
}
57
-
58
- public var isConnectionClosed : Bool {
57
+
58
+ var isConstraintFailure : Bool {
59
59
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 {
69
60
case . integrityConstraintViolation,
70
61
. restrictViolation,
71
62
. notNullViolation,
@@ -79,3 +70,37 @@ extension PostgresError: DatabaseError {
79
70
}
80
71
}
81
72
}
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