Rename to DbErr::Exec and DbErr::Conn
This commit is contained in:
parent
0298cfb6af
commit
30ac326d5c
@ -75,7 +75,7 @@ impl MockDatabaseTrait for MockDatabase {
|
|||||||
result: ExecResultHolder::Mock(std::mem::take(&mut self.exec_results[counter])),
|
result: ExecResultHolder::Mock(std::mem::take(&mut self.exec_results[counter])),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(DbErr::Execution)
|
Err(DbErr::Exec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,6 @@ impl Database {
|
|||||||
if crate::MockDatabaseConnector::accepts(string) {
|
if crate::MockDatabaseConnector::accepts(string) {
|
||||||
return Ok(crate::MockDatabaseConnector::connect(string).await?);
|
return Ok(crate::MockDatabaseConnector::connect(string).await?);
|
||||||
}
|
}
|
||||||
Err(DbErr::Connection)
|
Err(DbErr::Conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ impl SqlxMySqlConnector {
|
|||||||
SqlxMySqlPoolConnection { pool },
|
SqlxMySqlPoolConnection { pool },
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Err(DbErr::Connection)
|
Err(DbErr::Conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ impl SqlxMySqlPoolConnection {
|
|||||||
return Ok(res.into());
|
return Ok(res.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(DbErr::Execution)
|
Err(DbErr::Exec)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||||
|
@ -25,7 +25,7 @@ impl SqlxSqliteConnector {
|
|||||||
SqlxSqlitePoolConnection { pool },
|
SqlxSqlitePoolConnection { pool },
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Err(DbErr::Connection)
|
Err(DbErr::Conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ impl SqlxSqlitePoolConnection {
|
|||||||
return Ok(res.into());
|
return Ok(res.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(DbErr::Execution)
|
Err(DbErr::Exec)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||||
|
@ -227,7 +227,7 @@ where
|
|||||||
let model: Option<E::Model> = res?;
|
let model: Option<E::Model> = res?;
|
||||||
match model {
|
match model {
|
||||||
Some(model) => Ok(model.into_active_model()),
|
Some(model) => Ok(model.into_active_model()),
|
||||||
None => Err(DbErr::Execution),
|
None => Err(DbErr::Exec),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(A::default())
|
Ok(A::default())
|
||||||
|
12
src/error.rs
12
src/error.rs
@ -2,8 +2,8 @@ use std::{error, fmt};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DbErr {
|
pub enum DbErr {
|
||||||
Connection,
|
Conn,
|
||||||
Execution,
|
Exec,
|
||||||
Query,
|
Query,
|
||||||
#[cfg(feature = "sqlx-dep")]
|
#[cfg(feature = "sqlx-dep")]
|
||||||
Sqlx(sqlx::Error),
|
Sqlx(sqlx::Error),
|
||||||
@ -12,8 +12,8 @@ pub enum DbErr {
|
|||||||
impl fmt::Display for DbErr {
|
impl fmt::Display for DbErr {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Connection => write!(f, "{:?}", "Connection Error"),
|
Self::Conn => write!(f, "{:?}", "Connection Error"),
|
||||||
Self::Execution => write!(f, "{:?}", "Execution Error"),
|
Self::Exec => write!(f, "{:?}", "Execution Error"),
|
||||||
Self::Query => write!(f, "{:?}", "Query Error"),
|
Self::Query => write!(f, "{:?}", "Query Error"),
|
||||||
#[cfg(feature = "sqlx-dep")]
|
#[cfg(feature = "sqlx-dep")]
|
||||||
Self::Sqlx(e) => write!(f, "{:?}", e),
|
Self::Sqlx(e) => write!(f, "{:?}", e),
|
||||||
@ -24,8 +24,8 @@ impl fmt::Display for DbErr {
|
|||||||
impl error::Error for DbErr {
|
impl error::Error for DbErr {
|
||||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
Self::Connection => None,
|
Self::Conn => None,
|
||||||
Self::Execution => None,
|
Self::Exec => None,
|
||||||
Self::Query => None,
|
Self::Query => None,
|
||||||
#[cfg(feature = "sqlx-dep")]
|
#[cfg(feature = "sqlx-dep")]
|
||||||
Self::Sqlx(e) => Some(e),
|
Self::Sqlx(e) => Some(e),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user