Rename to DbErr::Exec and DbErr::Conn

This commit is contained in:
Chris Tsang 2021-06-30 21:21:06 +08:00
parent 0298cfb6af
commit 30ac326d5c
6 changed files with 13 additions and 13 deletions

View File

@ -75,7 +75,7 @@ impl MockDatabaseTrait for MockDatabase {
result: ExecResultHolder::Mock(std::mem::take(&mut self.exec_results[counter])),
})
} else {
Err(DbErr::Execution)
Err(DbErr::Exec)
}
}

View File

@ -29,6 +29,6 @@ impl Database {
if crate::MockDatabaseConnector::accepts(string) {
return Ok(crate::MockDatabaseConnector::connect(string).await?);
}
Err(DbErr::Connection)
Err(DbErr::Conn)
}
}

View File

@ -25,7 +25,7 @@ impl SqlxMySqlConnector {
SqlxMySqlPoolConnection { pool },
))
} else {
Err(DbErr::Connection)
Err(DbErr::Conn)
}
}
}
@ -46,7 +46,7 @@ impl SqlxMySqlPoolConnection {
return Ok(res.into());
}
}
Err(DbErr::Execution)
Err(DbErr::Exec)
}
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {

View File

@ -25,7 +25,7 @@ impl SqlxSqliteConnector {
SqlxSqlitePoolConnection { pool },
))
} else {
Err(DbErr::Connection)
Err(DbErr::Conn)
}
}
}
@ -46,7 +46,7 @@ impl SqlxSqlitePoolConnection {
return Ok(res.into());
}
}
Err(DbErr::Execution)
Err(DbErr::Exec)
}
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {

View File

@ -227,7 +227,7 @@ where
let model: Option<E::Model> = res?;
match model {
Some(model) => Ok(model.into_active_model()),
None => Err(DbErr::Execution),
None => Err(DbErr::Exec),
}
} else {
Ok(A::default())

View File

@ -2,8 +2,8 @@ use std::{error, fmt};
#[derive(Debug)]
pub enum DbErr {
Connection,
Execution,
Conn,
Exec,
Query,
#[cfg(feature = "sqlx-dep")]
Sqlx(sqlx::Error),
@ -12,8 +12,8 @@ pub enum DbErr {
impl fmt::Display for DbErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Connection => write!(f, "{:?}", "Connection Error"),
Self::Execution => write!(f, "{:?}", "Execution Error"),
Self::Conn => write!(f, "{:?}", "Connection Error"),
Self::Exec => write!(f, "{:?}", "Execution Error"),
Self::Query => write!(f, "{:?}", "Query Error"),
#[cfg(feature = "sqlx-dep")]
Self::Sqlx(e) => write!(f, "{:?}", e),
@ -24,8 +24,8 @@ impl fmt::Display for DbErr {
impl error::Error for DbErr {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::Connection => None,
Self::Execution => None,
Self::Conn => None,
Self::Exec => None,
Self::Query => None,
#[cfg(feature = "sqlx-dep")]
Self::Sqlx(e) => Some(e),