diff --git a/sqlx-core/src/error.rs b/sqlx-core/src/error.rs index bdca7e8abc..11d79ab6cf 100644 --- a/sqlx-core/src/error.rs +++ b/sqlx-core/src/error.rs @@ -212,6 +212,14 @@ pub trait DatabaseError: 'static + Send + Sync + StdError { None } + /// Returns the name of the table that was affected by the error, if applicable. + /// + /// ### Note + /// Currently only populated by the Postgres driver. + fn table(&self) -> Option<&str> { + None + } + /// Returns the kind of the error, if supported. /// /// ### Note diff --git a/sqlx-postgres/src/error.rs b/sqlx-postgres/src/error.rs index 8de58d5522..b9df865736 100644 --- a/sqlx-postgres/src/error.rs +++ b/sqlx-postgres/src/error.rs @@ -204,6 +204,10 @@ impl DatabaseError for PgDatabaseError { self.constraint() } + fn table(&self) -> Option<&str> { + self.table() + } + fn kind(&self) -> ErrorKind { match self.code() { error_codes::UNIQUE_VIOLATION => ErrorKind::UniqueViolation,