Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Sep 13, 2022
1 parent 36f09c5 commit 1225255
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion issues/324/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion issues/400/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>)))
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/driver/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl SqlxMySqlPoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -110,7 +110,7 @@ impl SqlxMySqlPoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -128,7 +128,7 @@ impl SqlxMySqlPoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -144,7 +144,7 @@ impl SqlxMySqlPoolConnection {
self.metric_callback.clone(),
)))
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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))
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/driver/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl SqlxPostgresPoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -110,7 +110,7 @@ impl SqlxPostgresPoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -128,7 +128,7 @@ impl SqlxPostgresPoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -144,7 +144,7 @@ impl SqlxPostgresPoolConnection {
self.metric_callback.clone(),
)))
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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))
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/driver/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl SqlxSqlitePoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -117,7 +117,7 @@ impl SqlxSqlitePoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -135,7 +135,7 @@ impl SqlxSqlitePoolConnection {
}
})
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -151,7 +151,7 @@ impl SqlxSqlitePoolConnection {
self.metric_callback.clone(),
)))
} else {
Err(DbErr::ConnFromPool)
Err(DbErr::ConnectionAcquire)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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))
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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),
}

Expand Down
2 changes: 1 addition & 1 deletion src/executor/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions src/executor/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
};
Expand All @@ -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,)*)))
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/executor/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1225255

Please sign in to comment.