mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-13 17:27:50 +00:00
Add DatabaseError::code
This commit is contained in:
parent
5cb0d9d9cc
commit
1d0100b35d
@ -177,6 +177,11 @@ pub trait DatabaseError: Display + Debug + Send + Sync {
|
||||
/// The primary, human-readable error message.
|
||||
fn message(&self) -> &str;
|
||||
|
||||
/// The (SQLSTATE) code for the error.
|
||||
fn code(&self) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn details(&self) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
@ -16,4 +16,8 @@ impl DatabaseError for MySqlError {
|
||||
fn message(&self) -> &str {
|
||||
&*self.0.error_message
|
||||
}
|
||||
|
||||
fn code(&self) -> Option<&str> {
|
||||
self.0.sql_state.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,10 @@ impl DatabaseError for PgError {
|
||||
&self.0.message
|
||||
}
|
||||
|
||||
fn code(&self) -> Option<&str> {
|
||||
Some(&self.0.code)
|
||||
}
|
||||
|
||||
fn details(&self) -> Option<&str> {
|
||||
self.0.detail.as_ref().map(|s| &**s)
|
||||
}
|
||||
|
||||
@ -7,8 +7,7 @@ use std::os::raw::c_int;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SqliteError {
|
||||
#[allow(dead_code)]
|
||||
code: c_int,
|
||||
code: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
@ -29,7 +28,7 @@ impl SqliteError {
|
||||
};
|
||||
|
||||
Self {
|
||||
code,
|
||||
code: code.to_string(),
|
||||
message: message.to_owned(),
|
||||
}
|
||||
}
|
||||
@ -45,4 +44,8 @@ impl DatabaseError for SqliteError {
|
||||
fn message(&self) -> &str {
|
||||
&self.message
|
||||
}
|
||||
|
||||
fn code(&self) -> Option<&str> {
|
||||
&self.code
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user