From 758e608e6c331df2a5900de7f932f9b498573ed1 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 7 Dec 2022 17:45:16 +0100 Subject: groundwork for downloads; cleanup --- src/db.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 9d862d6..cd32d1f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -122,7 +122,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> Result Result, Box> { + let data = format!("{}/data.db", config.data); + let connection = Connection::open(data)?; + + let mut versions: Vec<(String, String)> = Vec::new(); + let mut stmt = connection.prepare(format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str())?; + let id_iter = stmt.query_map([], |row| { + Ok(vec![row.get::(0)?, row.get::(1)?]) + })?; + + for ver in id_iter { + let out = ver?; + versions.push((out[0].to_owned(), out[1].to_owned())); + }; + + if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + + Ok(versions) +} + pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -248,6 +268,26 @@ pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Res Ok(versions) } +pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result, Box> { + let data = format!("{}/data.db", config.data); + let connection = Connection::open(data)?; + + let mut versions: Vec<(String, String)> = Vec::new(); + let mut stmt = connection.prepare(format!("SELECT mod_id, current_version FROM {}", list_id).as_str())?; + let id_iter = stmt.query_map([], |row| { + Ok(vec![row.get::(0)?, row.get::(1)?]) + })?; + + for ver in id_iter { + let out = ver?; + versions.push((out[0].to_owned(), out[1].to_owned())); + }; + + if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + + Ok(versions) +} + pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> Result<(), Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; -- cgit v1.2.3