From 5a1196c3c98a48028bf70576b5f946f7a0475e07 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 3 May 2023 11:56:17 +0200 Subject: added id to db lookup --- src/db.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index abfe1dd..6c7e4f8 100644 --- a/src/db.rs +++ b/src/db.rs @@ -50,8 +50,6 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box MLE { - //TODO check if "slug" is id - let data = format!("{}/data.db", data); let connection = Connection::open(data)?; @@ -64,6 +62,15 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE { for id in id_iter { mod_id = id?; } + //get from id if no slug found + if mod_id.is_empty() { + let mut stmt = connection.prepare("SELECT id FROM mods WHERE id = ?")?; + let id_iter = stmt.query_map([slug], |row| row.get::(0))?; + + for id in id_iter { + mod_id = id?; + } + } //get from title if no id found from slug if mod_id.is_empty() { let mut stmt = connection.prepare("SELECT id FROM mods WHERE title = ?")?; -- cgit v1.2.3