mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-27 21:51:22 +00:00
Add constraint method to DatabaseError trait
Override `constraint` method for `PgDatabaseError`.
This commit is contained in:
committed by
Ryan Leckey
parent
d5e0f1b92b
commit
68cf2f9cdb
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user