From 4520abd55e88a2d9eaf873197b92d1fb40091f88 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 11 Feb 2022 09:58:35 -0300 Subject: [PATCH] Checking what happens when a query doesn't return a value --- sqlxtest/src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sqlxtest/src/main.rs b/sqlxtest/src/main.rs index f18fc5a..b1feb5f 100644 --- a/sqlxtest/src/main.rs +++ b/sqlxtest/src/main.rs @@ -83,11 +83,14 @@ async fn main() -> Result<(), sqlx::Error> { repo.save(&record).await?; } else if command == "remove" { println!("Should remove \"{}\"", value); - if let Ok(record) = repo.find_by_description(&value).await { - repo.delete(&record).await?; - println!("Removed"); - } else { - println!("Label does not exist"); + match repo.find_by_description(&value).await { + Ok(record) => { + repo.delete(&record).await?; + println!("Removed"); + } + Err(err) => { + println!("Label does not exist: {:?}", err); + } } } Ok(())