Trait sqlx_core::error::DatabaseError
source · pub trait DatabaseError: 'static + Send + Sync + StdError {
// Required methods
fn message(&self) -> &str;
fn kind(&self) -> ErrorKind;
// Provided methods
fn code(&self) -> Option<Cow<'_, str>> { ... }
fn constraint(&self) -> Option<&str> { ... }
fn table(&self) -> Option<&str> { ... }
fn is_unique_violation(&self) -> bool { ... }
fn is_foreign_key_violation(&self) -> bool { ... }
fn is_check_violation(&self) -> bool { ... }
}
Expand description
An error that was returned from the database.
Required Methods§
Provided Methods§
sourcefn constraint(&self) -> Option<&str>
fn constraint(&self) -> Option<&str>
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.
sourcefn table(&self) -> Option<&str>
fn table(&self) -> Option<&str>
Returns the name of the table that was affected by the error, if applicable.
§Note
Currently only populated by the Postgres driver.
sourcefn is_unique_violation(&self) -> bool
fn is_unique_violation(&self) -> bool
Returns whether the error kind is a violation of a unique/primary key constraint.
sourcefn is_foreign_key_violation(&self) -> bool
fn is_foreign_key_violation(&self) -> bool
Returns whether the error kind is a violation of a foreign key.
sourcefn is_check_violation(&self) -> bool
fn is_check_violation(&self) -> bool
Returns whether the error kind is a violation of a check.
Implementations§
source§impl dyn DatabaseError
impl dyn DatabaseError
sourcepub fn downcast_ref<E: DatabaseError>(&self) -> &E
pub fn downcast_ref<E: DatabaseError>(&self) -> &E
Downcast a reference to this generic database error to a specific database error type.
§Panics
Panics if the database error type is not E
. This is a deliberate contrast from
Error::downcast_ref
which returns Option<&E>
. In normal usage, you should know the
specific error type. In other cases, use try_downcast_ref
.
sourcepub fn downcast<E: DatabaseError>(self: Box<Self>) -> Box<E>
pub fn downcast<E: DatabaseError>(self: Box<Self>) -> Box<E>
Downcast this generic database error to a specific database error type.
§Panics
Panics if the database error type is not E
. This is a deliberate contrast from
Error::downcast
which returns Option<E>
. In normal usage, you should know the
specific error type. In other cases, use try_downcast
.
sourcepub fn try_downcast_ref<E: DatabaseError>(&self) -> Option<&E>
pub fn try_downcast_ref<E: DatabaseError>(&self) -> Option<&E>
Downcast a reference to this generic database error to a specific database error type.
sourcepub fn try_downcast<E: DatabaseError>(
self: Box<Self>,
) -> Result<Box<E>, Box<Self>>
pub fn try_downcast<E: DatabaseError>( self: Box<Self>, ) -> Result<Box<E>, Box<Self>>
Downcast this generic database error to a specific database error type.