From 9c984cef9a2d0fb223635617934959480e8ca2df Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 19 Feb 2023 11:49:23 +0100 Subject: Added adding of specific mod-version --- src/db.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index ecc6854..a7c149c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -82,23 +82,29 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE { Ok(mod_id) } -pub fn mods_get_title(config: Cfg, id: &str) -> MLE { +pub struct ModInfo { + pub slug: String, + pub title: String, +} + +pub fn mods_get_info(config: Cfg, id: &str) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - let mut mod_name = String::new(); - let mut stmt = connection.prepare("SELECT title FROM mods WHERE id = ?")?; + let mut mod_info: Option = None; + let mut stmt = connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?; let name_iter = stmt.query_map([id], |row| { - row.get::(0) + Ok(vec![row.get::(0)?, row.get::(1)?]) })?; - for name in name_iter { - mod_name = name?; + for info in name_iter { + let i = info?; + mod_info = Some(ModInfo { title: String::from(&i[0]), slug: String::from(&i[1]) }); }; - match mod_name.is_empty() { + match mod_info.is_none() { true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")), - false => Ok(mod_name), + false => Ok(mod_info.unwrap()), } } -- cgit v1.2.3