Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecordNotFound -> RecordNotUpdated #1425

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
RecordNotFound -> RecordNotUpdated
  • Loading branch information
tyt2y3 committed Jan 25, 2023
commit b3e4d1c1cf30217d904860e6d36bc51c5e78b123
11 changes: 7 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ pub enum DbErr {
/// A migration error
#[error("Migration Error: {0}")]
Migration(String),
/// None of the records are being inserted into the database,
/// if you insert with upsert expression that means
/// all of them conflict with existing records in the database
#[error("None of the records are being inserted")]
/// None of the records are inserted,
/// that probably means all of them conflict with existing records in the table
#[error("None of the records are inserted")]
RecordNotInserted,
/// None of the records are updated, that means a WHERE condition has no matches.
/// May be the table is empty or the record does not exist
#[error("None of the records are updated")]
RecordNotUpdated,
}

/// Runtime error
Expand Down
20 changes: 5 additions & 15 deletions src/executor/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ impl Updater {
let statement = builder.build(&self.query);
let result = db.execute(statement).await?;
if self.check_record_exists && result.rows_affected() == 0 {
return Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned(),
));
return Err(DbErr::RecordNotUpdated);
}
Ok(UpdateResult {
rows_affected: result.rows_affected(),
Expand Down Expand Up @@ -114,9 +112,7 @@ impl Updater {
// If we got `None` then we are updating a row that does not exist.
match found {
Some(model) => Ok(model),
None => Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned(),
)),
None => Err(DbErr::RecordNotUpdated),
}
}
false => {
Expand Down Expand Up @@ -216,9 +212,7 @@ mod tests {
}
.update(&db)
.await,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
Err(DbErr::RecordNotUpdated)
);

assert_eq!(
Expand All @@ -228,9 +222,7 @@ mod tests {
})
.exec(&db)
.await,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
Err(DbErr::RecordNotUpdated)
);

assert_eq!(
Expand All @@ -240,9 +232,7 @@ mod tests {
})
.exec(&db)
.await,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
Err(DbErr::RecordNotUpdated)
);

assert_eq!(
Expand Down
7 changes: 1 addition & 6 deletions tests/byte_primary_key_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ pub async fn create_and_update(db: &DatabaseConnection) -> Result<(), DbErr> {
.exec(db)
.await;

assert_eq!(
update_res,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
);
assert_eq!(update_res, Err(DbErr::RecordNotUpdated));

let update_res = Entity::update(updated_active_model)
.filter(Column::Id.eq(vec![1_u8, 2_u8, 3_u8])) // annotate it as Vec<u8> explicitly
Expand Down
7 changes: 1 addition & 6 deletions tests/crud/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ pub async fn test_update_deleted_customer(db: &DbConn) {

let customer_update_res = customer.update(db).await;

assert_eq!(
customer_update_res,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
);
assert_eq!(customer_update_res, Err(DbErr::RecordNotUpdated));

assert_eq!(Customer::find().count(db).await.unwrap(), init_n_customers);

Expand Down
7 changes: 1 addition & 6 deletions tests/string_primary_key_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ pub async fn create_and_update_repository(db: &DatabaseConnection) -> Result<(),
.exec(db)
.await;

assert_eq!(
update_res,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
);
assert_eq!(update_res, Err(DbErr::RecordNotUpdated));

let update_res = Repository::update(updated_active_model)
.filter(repository::Column::Id.eq("unique-id-002".to_owned()))
Expand Down
7 changes: 1 addition & 6 deletions tests/uuid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ pub async fn create_and_update_metadata(db: &DatabaseConnection) -> Result<(), D
.exec(db)
.await;

assert_eq!(
update_res,
Err(DbErr::RecordNotFound(
"None of the database rows are affected".to_owned()
))
);
assert_eq!(update_res, Err(DbErr::RecordNotUpdated));

Ok(())
}