Trait sqlx::error::DatabaseError

source ·
pub trait DatabaseError: 'static + Send + Sync + Error {
    // Required methods
    fn message(&self) -> &str;
    fn kind(&self) -> ErrorKind;

    // Provided methods
    fn code(&self) -> Option<Cow<'_, str>> { ... }
    fn constraint(&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§

source

fn message(&self) -> &str

The primary, human-readable error message.

source

fn kind(&self) -> ErrorKind

Returns the kind of the error, if supported.

Note

Not all back-ends behave the same when reporting the error code.

Provided Methods§

source

fn code(&self) -> Option<Cow<'_, str>>

The (SQLSTATE) code for the error.

source

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.

source

fn is_unique_violation(&self) -> bool

Returns whether the error kind is a violation of a unique/primary key constraint.

source

fn is_foreign_key_violation(&self) -> bool

Returns whether the error kind is a violation of a foreign key.

source

fn is_check_violation(&self) -> bool

Returns whether the error kind is a violation of a check.

Implementations§

source§

impl dyn DatabaseError

source

pub fn downcast_ref<E>(&self) -> &Ewhere E: DatabaseError,

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.

source

pub fn downcast<E>(self: Box<dyn DatabaseError, Global>) -> Box<E, Global>where E: DatabaseError,

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.

source

pub fn try_downcast_ref<E>(&self) -> Option<&E>where E: DatabaseError,

Downcast a reference to this generic database error to a specific database error type.

source

pub fn try_downcast<E>( self: Box<dyn DatabaseError, Global> ) -> Result<Box<E, Global>, Box<dyn DatabaseError, Global>>where E: DatabaseError,

Downcast this generic database error to a specific database error type.

Implementations on Foreign Types§

source§

impl DatabaseError for MySqlDatabaseError

source§

fn message(&self) -> &str

source§

fn code(&self) -> Option<Cow<'_, str>>

source§

fn kind(&self) -> ErrorKind

source§

impl DatabaseError for PgDatabaseError

source§

fn message(&self) -> &str

source§

fn code(&self) -> Option<Cow<'_, str>>

source§

fn constraint(&self) -> Option<&str>

source§

fn kind(&self) -> ErrorKind

source§

impl DatabaseError for SqliteError

source§

fn code(&self) -> Option<Cow<'_, str>>

The extended result code.

source§

fn message(&self) -> &str

source§

fn kind(&self) -> ErrorKind

Implementors§