Address comments

This commit is contained in:
Chris Tsang 2022-09-14 00:28:24 +08:00
parent 36f09c524e
commit 1225255431
9 changed files with 30 additions and 30 deletions

View File

@ -26,7 +26,7 @@ macro_rules! impl_try_from_u64_err {
($newtype: ident) => { ($newtype: ident) => {
impl sea_orm::TryFromU64 for $newtype { impl sea_orm::TryFromU64 for $newtype {
fn try_from_u64(_n: u64) -> Result<Self, sea_orm::DbErr> { fn try_from_u64(_n: u64) -> Result<Self, sea_orm::DbErr> {
Err(sea_orm::DbErr::CannotConvertFromU64(stringify!($newtype))) Err(sea_orm::DbErr::ConvertFromU64(stringify!($newtype)))
} }
} }
}; };

View File

@ -31,7 +31,7 @@ impl<T> From<AccountId<T>> for Uuid {
impl<T> sea_orm::TryFromU64 for AccountId<T> { impl<T> sea_orm::TryFromU64 for AccountId<T> {
fn try_from_u64(_n: u64) -> Result<Self, sea_orm::DbErr> { fn try_from_u64(_n: u64) -> Result<Self, sea_orm::DbErr> {
Err(sea_orm::DbErr::CannotConvertFromU64(stringify!(AccountId<T>))) Err(sea_orm::DbErr::ConvertFromU64(stringify!(AccountId<T>)))
} }
} }

View File

@ -89,7 +89,7 @@ impl SqlxMySqlPoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -110,7 +110,7 @@ impl SqlxMySqlPoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -128,7 +128,7 @@ impl SqlxMySqlPoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -144,7 +144,7 @@ impl SqlxMySqlPoolConnection {
self.metric_callback.clone(), self.metric_callback.clone(),
))) )))
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -154,7 +154,7 @@ impl SqlxMySqlPoolConnection {
if let Ok(conn) = self.pool.acquire().await { if let Ok(conn) = self.pool.acquire().await {
DatabaseTransaction::new_mysql(conn, self.metric_callback.clone()).await DatabaseTransaction::new_mysql(conn, self.metric_callback.clone()).await
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -175,7 +175,7 @@ impl SqlxMySqlPoolConnection {
.map_err(|e| TransactionError::Connection(e))?; .map_err(|e| TransactionError::Connection(e))?;
transaction.run(callback).await transaction.run(callback).await
} else { } else {
Err(TransactionError::Connection(DbErr::ConnFromPool)) Err(TransactionError::Connection(DbErr::ConnectionAcquire))
} }
} }

View File

@ -89,7 +89,7 @@ impl SqlxPostgresPoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -110,7 +110,7 @@ impl SqlxPostgresPoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -128,7 +128,7 @@ impl SqlxPostgresPoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -144,7 +144,7 @@ impl SqlxPostgresPoolConnection {
self.metric_callback.clone(), self.metric_callback.clone(),
))) )))
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -154,7 +154,7 @@ impl SqlxPostgresPoolConnection {
if let Ok(conn) = self.pool.acquire().await { if let Ok(conn) = self.pool.acquire().await {
DatabaseTransaction::new_postgres(conn, self.metric_callback.clone()).await DatabaseTransaction::new_postgres(conn, self.metric_callback.clone()).await
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -175,7 +175,7 @@ impl SqlxPostgresPoolConnection {
.map_err(|e| TransactionError::Connection(e))?; .map_err(|e| TransactionError::Connection(e))?;
transaction.run(callback).await transaction.run(callback).await
} else { } else {
Err(TransactionError::Connection(DbErr::ConnFromPool)) Err(TransactionError::Connection(DbErr::ConnectionAcquire))
} }
} }

View File

@ -96,7 +96,7 @@ impl SqlxSqlitePoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -117,7 +117,7 @@ impl SqlxSqlitePoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -135,7 +135,7 @@ impl SqlxSqlitePoolConnection {
} }
}) })
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -151,7 +151,7 @@ impl SqlxSqlitePoolConnection {
self.metric_callback.clone(), self.metric_callback.clone(),
))) )))
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -161,7 +161,7 @@ impl SqlxSqlitePoolConnection {
if let Ok(conn) = self.pool.acquire().await { if let Ok(conn) = self.pool.acquire().await {
DatabaseTransaction::new_sqlite(conn, self.metric_callback.clone()).await DatabaseTransaction::new_sqlite(conn, self.metric_callback.clone()).await
} else { } else {
Err(DbErr::ConnFromPool) Err(DbErr::ConnectionAcquire)
} }
} }
@ -182,7 +182,7 @@ impl SqlxSqlitePoolConnection {
.map_err(|e| TransactionError::Connection(e))?; .map_err(|e| TransactionError::Connection(e))?;
transaction.run(callback).await transaction.run(callback).await
} else { } else {
Err(TransactionError::Connection(DbErr::ConnFromPool)) Err(TransactionError::Connection(DbErr::ConnectionAcquire))
} }
} }

View File

@ -7,7 +7,7 @@ use thiserror::Error;
pub enum DbErr { pub enum DbErr {
/// This error can happen when the connection pool is fully-utilized /// This error can happen when the connection pool is fully-utilized
#[error("Failed to acquire connection from pool")] #[error("Failed to acquire connection from pool")]
ConnFromPool, ConnectionAcquire,
/// Runtime type conversion error /// Runtime type conversion error
#[error("Error converting `{from}` into `{into}`: {source}")] #[error("Error converting `{from}` into `{into}`: {source}")]
TryIntoErr { TryIntoErr {
@ -20,14 +20,14 @@ pub enum DbErr {
}, },
/// Type error: the specified type cannot be converted from u64. This is not a runtime error. /// Type error: the specified type cannot be converted from u64. This is not a runtime error.
#[error("Type '{0}' cannot be converted from u64")] #[error("Type '{0}' cannot be converted from u64")]
CannotConvertFromU64(&'static str), ConvertFromU64(&'static str),
/// After an insert statement it was impossible to retrieve the last_insert_id /// After an insert statement it was impossible to retrieve the last_insert_id
#[error("Failed to unpack last_insert_id")] #[error("Failed to unpack last_insert_id")]
InsertCouldNotUnpackInsertId, UnpackInsertId,
/// When updating, a model should know it's primary key to check /// When updating, a model should know it's primary key to check
/// if the record has been correctly updated, otherwise this error will occur /// if the record has been correctly updated, otherwise this error will occur
#[error("Failed to get primary key from model")] #[error("Failed to get primary key from model")]
UpdateCouldNotGetPrimaryKey, UpdateGetPrimeryKey,
/// There was a problem with the database connection /// There was a problem with the database connection
#[error("Connection Error: {0}")] #[error("Connection Error: {0}")]
Conn(#[source] RuntimeErr), Conn(#[source] RuntimeErr),
@ -57,12 +57,12 @@ pub enum DbErr {
/// Runtime error /// Runtime error
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum RuntimeErr { pub enum RuntimeErr {
#[cfg(feature = "sqlx-dep")]
/// SQLx Error /// SQLx Error
#[cfg(feature = "sqlx-dep")]
#[error("{0}")] #[error("{0}")]
SqlxError(SqlxError), SqlxError(SqlxError),
#[error("{0}")]
/// Error generated from within SeaORM /// Error generated from within SeaORM
#[error("{0}")]
Internal(String), Internal(String),
} }

View File

@ -130,7 +130,7 @@ where
Some(value_tuple) => FromValueTuple::from_value_tuple(value_tuple), Some(value_tuple) => FromValueTuple::from_value_tuple(value_tuple),
None => match last_insert_id_opt { None => match last_insert_id_opt {
Some(last_insert_id) => last_insert_id, Some(last_insert_id) => last_insert_id,
None => return Err(DbErr::InsertCouldNotUnpackInsertId), None => return Err(DbErr::UnpackInsertId),
}, },
}; };
Ok(InsertResult { last_insert_id }) Ok(InsertResult { last_insert_id })

View File

@ -709,7 +709,7 @@ macro_rules! try_from_u64_err {
( $type: ty ) => { ( $type: ty ) => {
impl TryFromU64 for $type { impl TryFromU64 for $type {
fn try_from_u64(_: u64) -> Result<Self, DbErr> { fn try_from_u64(_: u64) -> Result<Self, DbErr> {
Err(DbErr::CannotConvertFromU64(stringify!($type))) Err(DbErr::ConvertFromU64(stringify!($type)))
} }
} }
}; };
@ -720,7 +720,7 @@ macro_rules! try_from_u64_err {
$( $gen_type: TryFromU64, )* $( $gen_type: TryFromU64, )*
{ {
fn try_from_u64(_: u64) -> Result<Self, DbErr> { fn try_from_u64(_: u64) -> Result<Self, DbErr> {
Err(DbErr::CannotConvertFromU64(stringify!($($gen_type,)*))) Err(DbErr::ConvertFromU64(stringify!($($gen_type,)*)))
} }
} }
}; };

View File

@ -122,7 +122,7 @@ where
Updater::new(query).check_record_exists().exec(db).await?; Updater::new(query).check_record_exists().exec(db).await?;
let primary_key_value = match model.get_primary_key_value() { let primary_key_value = match model.get_primary_key_value() {
Some(val) => FromValueTuple::from_value_tuple(val), Some(val) => FromValueTuple::from_value_tuple(val),
None => return Err(DbErr::UpdateCouldNotGetPrimaryKey), None => return Err(DbErr::UpdateGetPrimeryKey),
}; };
let found = <A::Entity as EntityTrait>::find_by_id(primary_key_value) let found = <A::Entity as EntityTrait>::find_by_id(primary_key_value)
.one(db) .one(db)