From b3ac70952669822c2d3f693804d41ec05c040431 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 24 Feb 2025 10:46:13 +0300 Subject: [PATCH] fix(missing url): handle missing URLs gracefully --- src/db.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/db.rs b/src/db.rs index a090a4e..b90b553 100644 --- a/src/db.rs +++ b/src/db.rs @@ -132,7 +132,22 @@ mod db_impl { // Retrieve all items from the database for a specific URL pub async fn get_items_by_url(&self, url: &str) -> Result, Error> { let conn = self.conn.lock().await; - let url_id: i64 = conn.query_row("SELECT id FROM urls WHERE url = ?", &[url], |row| row.get(0))?; + + let url_id: Option = match conn.query_row( + "SELECT id FROM urls WHERE url = ?", + &[url], + |row| row.get(0) + ) { + Ok(id) => Some(id), + Err(rusqlite::Error::QueryReturnedNoRows) => None, + Err(e) => return Err(e), + }; + + let url_id = match url_id { + Some(id) => id, + None => return Ok(Vec::new()), // Return empty list if URL not found + }; + let mut stmt = conn.prepare( "SELECT i.id, i.name, i.description, i.wikidata_id, p.name AS prop_name, ip.value