Add constraint method to DatabaseError trait

Override `constraint` method for `PgDatabaseError`.
This commit is contained in:
Florian Hübsch
2021-01-20 09:37:38 +01:00
committed by Ryan Leckey
parent d5e0f1b92b
commit 68cf2f9cdb
4 changed files with 55 additions and 0 deletions

View File

@@ -158,6 +158,15 @@ pub trait DatabaseError: 'static + Send + Sync + StdError {
#[doc(hidden)]
fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static>;
/// Returns the name of the constraint that triggered the error, if applicable.
/// If the error was caused by a conflict of a unique index, this will be the index name.
///
/// ### Note
/// Currently only populated by the Postgres driver.
fn constraint(&self) -> Option<&str> {
None
}
}
impl dyn DatabaseError {

View File

@@ -184,4 +184,8 @@ impl DatabaseError for PgDatabaseError {
fn into_error(self: Box<Self>) -> Box<dyn Error + Send + Sync + 'static> {
self
}
fn constraint(&self) -> Option<&str> {
self.constraint()
}
}