We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ad9268d commit 81f7bc0Copy full SHA for 81f7bc0
postgres/src/error.rs
@@ -31,6 +31,15 @@ impl Error {
31
pub fn is_row_not_found(&self) -> bool {
32
matches!(self.kind, ErrorKind::RowNotFound)
33
}
34
+
35
+ /// Whether this is a duplicate key error (unique constraint violation).
36
+ pub fn is_duplicate_key(&self) -> bool {
37
+ if let ErrorKind::Postgres(err) = &self.kind {
38
+ err.code() == Some(&tokio_postgres::error::SqlState::UNIQUE_VIOLATION)
39
+ } else {
40
+ false
41
+ }
42
43
44
45
impl error::Error for Error {
0 commit comments