@@ -3,9 +3,9 @@ import FluentSQL
33import PostgresKit
44import PostgresNIO
55
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 {
99 case . syntaxErrorOrAccessRuleViolation,
1010 . syntaxError,
1111 . insufficientPrivilege,
@@ -54,18 +54,9 @@ extension PostgresError: DatabaseError {
5454 return false
5555 }
5656 }
57-
58- public var 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