Address comments
This commit is contained in:
parent
36f09c524e
commit
1225255431
@ -26,7 +26,7 @@ macro_rules! impl_try_from_u64_err {
|
||||
($newtype: ident) => {
|
||||
impl sea_orm::TryFromU64 for $newtype {
|
||||
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)))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ impl<T> From<AccountId<T>> for Uuid {
|
||||
|
||||
impl<T> sea_orm::TryFromU64 for AccountId<T> {
|
||||
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>)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl SqlxMySqlPoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ impl SqlxMySqlPoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ impl SqlxMySqlPoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ impl SqlxMySqlPoolConnection {
|
||||
self.metric_callback.clone(),
|
||||
)))
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ impl SqlxMySqlPoolConnection {
|
||||
if let Ok(conn) = self.pool.acquire().await {
|
||||
DatabaseTransaction::new_mysql(conn, self.metric_callback.clone()).await
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ impl SqlxMySqlPoolConnection {
|
||||
.map_err(|e| TransactionError::Connection(e))?;
|
||||
transaction.run(callback).await
|
||||
} else {
|
||||
Err(TransactionError::Connection(DbErr::ConnFromPool))
|
||||
Err(TransactionError::Connection(DbErr::ConnectionAcquire))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ impl SqlxPostgresPoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ impl SqlxPostgresPoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ impl SqlxPostgresPoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ impl SqlxPostgresPoolConnection {
|
||||
self.metric_callback.clone(),
|
||||
)))
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ impl SqlxPostgresPoolConnection {
|
||||
if let Ok(conn) = self.pool.acquire().await {
|
||||
DatabaseTransaction::new_postgres(conn, self.metric_callback.clone()).await
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ impl SqlxPostgresPoolConnection {
|
||||
.map_err(|e| TransactionError::Connection(e))?;
|
||||
transaction.run(callback).await
|
||||
} else {
|
||||
Err(TransactionError::Connection(DbErr::ConnFromPool))
|
||||
Err(TransactionError::Connection(DbErr::ConnectionAcquire))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ impl SqlxSqlitePoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ impl SqlxSqlitePoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ impl SqlxSqlitePoolConnection {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ impl SqlxSqlitePoolConnection {
|
||||
self.metric_callback.clone(),
|
||||
)))
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ impl SqlxSqlitePoolConnection {
|
||||
if let Ok(conn) = self.pool.acquire().await {
|
||||
DatabaseTransaction::new_sqlite(conn, self.metric_callback.clone()).await
|
||||
} else {
|
||||
Err(DbErr::ConnFromPool)
|
||||
Err(DbErr::ConnectionAcquire)
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ impl SqlxSqlitePoolConnection {
|
||||
.map_err(|e| TransactionError::Connection(e))?;
|
||||
transaction.run(callback).await
|
||||
} else {
|
||||
Err(TransactionError::Connection(DbErr::ConnFromPool))
|
||||
Err(TransactionError::Connection(DbErr::ConnectionAcquire))
|
||||
}
|
||||
}
|
||||
|
||||
|
12
src/error.rs
12
src/error.rs
@ -7,7 +7,7 @@ use thiserror::Error;
|
||||
pub enum DbErr {
|
||||
/// This error can happen when the connection pool is fully-utilized
|
||||
#[error("Failed to acquire connection from pool")]
|
||||
ConnFromPool,
|
||||
ConnectionAcquire,
|
||||
/// Runtime type conversion error
|
||||
#[error("Error converting `{from}` into `{into}`: {source}")]
|
||||
TryIntoErr {
|
||||
@ -20,14 +20,14 @@ pub enum DbErr {
|
||||
},
|
||||
/// Type error: the specified type cannot be converted from u64. This is not a runtime error.
|
||||
#[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
|
||||
#[error("Failed to unpack last_insert_id")]
|
||||
InsertCouldNotUnpackInsertId,
|
||||
UnpackInsertId,
|
||||
/// When updating, a model should know it's primary key to check
|
||||
/// if the record has been correctly updated, otherwise this error will occur
|
||||
#[error("Failed to get primary key from model")]
|
||||
UpdateCouldNotGetPrimaryKey,
|
||||
UpdateGetPrimeryKey,
|
||||
/// There was a problem with the database connection
|
||||
#[error("Connection Error: {0}")]
|
||||
Conn(#[source] RuntimeErr),
|
||||
@ -57,12 +57,12 @@ pub enum DbErr {
|
||||
/// Runtime error
|
||||
#[derive(Error, Debug)]
|
||||
pub enum RuntimeErr {
|
||||
#[cfg(feature = "sqlx-dep")]
|
||||
/// SQLx Error
|
||||
#[cfg(feature = "sqlx-dep")]
|
||||
#[error("{0}")]
|
||||
SqlxError(SqlxError),
|
||||
#[error("{0}")]
|
||||
/// Error generated from within SeaORM
|
||||
#[error("{0}")]
|
||||
Internal(String),
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ where
|
||||
Some(value_tuple) => FromValueTuple::from_value_tuple(value_tuple),
|
||||
None => match last_insert_id_opt {
|
||||
Some(last_insert_id) => last_insert_id,
|
||||
None => return Err(DbErr::InsertCouldNotUnpackInsertId),
|
||||
None => return Err(DbErr::UnpackInsertId),
|
||||
},
|
||||
};
|
||||
Ok(InsertResult { last_insert_id })
|
||||
|
@ -709,7 +709,7 @@ macro_rules! try_from_u64_err {
|
||||
( $type: ty ) => {
|
||||
impl TryFromU64 for $type {
|
||||
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, )*
|
||||
{
|
||||
fn try_from_u64(_: u64) -> Result<Self, DbErr> {
|
||||
Err(DbErr::CannotConvertFromU64(stringify!($($gen_type,)*)))
|
||||
Err(DbErr::ConvertFromU64(stringify!($($gen_type,)*)))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -122,7 +122,7 @@ where
|
||||
Updater::new(query).check_record_exists().exec(db).await?;
|
||||
let primary_key_value = match model.get_primary_key_value() {
|
||||
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)
|
||||
.one(db)
|
||||
|
Loading…
x
Reference in New Issue
Block a user