From c7ecf3019a75dc0ab1a0aefeb9b880899fc8a231 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 29 May 2023 18:01:12 +0200 Subject: cargo fmt and add fmt file --- src/db.rs | 128 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 40 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 1958fc5..49db2fd 100644 --- a/src/db.rs +++ b/src/db.rs @@ -21,7 +21,9 @@ pub fn mods_insert(config: &Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { Ok(()) } -pub fn mods_get_all_ids(config: &Cfg) -> Result, Box> { +pub fn mods_get_all_ids( + config: &Cfg, +) -> Result, Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -64,8 +66,10 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE { } //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))?; + 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?; @@ -73,8 +77,10 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE { } //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 = ?")?; - let id_iter = stmt.query_map([slug], |row| row.get::(0))?; + let mut stmt = + connection.prepare("SELECT id FROM mods WHERE title = ?")?; + let id_iter = + stmt.query_map([slug], |row| row.get::(0))?; for id in id_iter { mod_id = id?; @@ -98,7 +104,8 @@ pub fn mods_get_info(config: &Cfg, id: &str) -> MLE { let connection = Connection::open(data)?; let mut mod_info: Option = None; - let mut stmt = connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?; + let mut stmt = + connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?; let name_iter = stmt.query_map([id], |row| { Ok(vec![ row.get::(0)?, @@ -135,7 +142,10 @@ pub struct DBModlistVersions { pub versions: String, } -pub fn mods_get_versions(config: &Cfg, mods: Vec) -> MLE> { +pub fn mods_get_versions( + config: &Cfg, + mods: Vec, +) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -153,8 +163,9 @@ pub fn mods_get_versions(config: &Cfg, mods: Vec) -> MLE = Vec::new(); - let mut stmt = connection - .prepare(format!("SELECT id, versions, title FROM mods {}", wherestr).as_str())?; + let mut stmt = connection.prepare( + format!("SELECT id, versions, title FROM mods {}", wherestr).as_str(), + )?; let id_iter = stmt.query_map([], |row| { Ok(vec![ row.get::(0)?, @@ -218,7 +229,8 @@ pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE> { let connection = Connection::open(data).unwrap(); let mut mod_ids: Vec = Vec::new(); - let mut stmt = connection.prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; + let mut stmt = connection + .prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { @@ -261,7 +273,8 @@ pub fn userlist_get_applicable_versions( ) .as_str(), )?; - let ver_iter = stmt.query_map([mod_id], |row| row.get::(0))?; + let ver_iter = + stmt.query_map([mod_id], |row| row.get::(0))?; for ver in ver_iter { version = ver?; @@ -281,8 +294,9 @@ pub fn userlist_get_all_applicable_versions_with_mods( 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 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)?, @@ -302,14 +316,21 @@ pub fn userlist_get_all_applicable_versions_with_mods( Ok(versions) } -pub fn userlist_get_current_version(config: &Cfg, list_id: &str, mod_id: &str) -> MLE { +pub fn userlist_get_current_version( + config: &Cfg, + list_id: &str, + mod_id: &str, +) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); - let mut stmt = connection - .prepare(format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([&mod_id], |row| row.get::(0))?; + let mut stmt = connection.prepare( + format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id) + .as_str(), + )?; + let ver_iter = + stmt.query_map([&mod_id], |row| row.get::(0))?; for ver in ver_iter { version = ver?; @@ -321,13 +342,16 @@ pub fn userlist_get_current_version(config: &Cfg, list_id: &str, mod_id: &str) - } } -pub fn userlist_get_all_current_version_ids(config: &Cfg, list_id: String) -> MLE> { +pub fn userlist_get_all_current_version_ids( + config: &Cfg, + list_id: String, +) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut versions: Vec = Vec::new(); - let mut stmt = - connection.prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; + let mut stmt = connection + .prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { @@ -349,8 +373,9 @@ pub fn userlist_get_all_current_versions_with_mods( 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 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)?, @@ -373,14 +398,21 @@ pub fn userlist_get_all_current_versions_with_mods( Ok(versions) } -pub fn userlist_get_set_version(config: &Cfg, list_id: &str, mod_id: &str) -> MLE { +pub fn userlist_get_set_version( + config: &Cfg, + list_id: &str, + mod_id: &str, +) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut set_version: bool = false; - let mut stmt = connection - .prepare(format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([&mod_id], |row| row.get::(0))?; + let mut stmt = connection.prepare( + format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id) + .as_str(), + )?; + let ver_iter = + stmt.query_map([&mod_id], |row| row.get::(0))?; for ver in ver_iter { set_version = ver?; @@ -413,11 +445,16 @@ pub fn userlist_add_disabled_versions( let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; - let currently_disabled_versions = - userlist_get_disabled_versions(config, String::from(&list_id), String::from(&mod_id))?; + let currently_disabled_versions = userlist_get_disabled_versions( + config, + String::from(&list_id), + String::from(&mod_id), + )?; let disabled_versions = match currently_disabled_versions == "NONE" { true => disabled_version, - false => format!("{}|{}", currently_disabled_versions, disabled_version), + false => { + format!("{}|{}", currently_disabled_versions, disabled_version) + } }; connection.execute( @@ -440,9 +477,12 @@ pub fn userlist_get_disabled_versions( let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); - let mut stmt = connection - .prepare(format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([mod_id], |row| row.get::(0))?; + let mut stmt = connection.prepare( + format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id) + .as_str(), + )?; + let ver_iter = + stmt.query_map([mod_id], |row| row.get::(0))?; for ver in ver_iter { version = ver?; @@ -462,8 +502,9 @@ pub fn userlist_get_all_downloads( let connection = Connection::open(data).unwrap(); let mut links: Vec = Vec::new(); - let mut stmt = - connection.prepare(format!("SELECT current_download FROM {}", list_id).as_str())?; + let mut stmt = connection.prepare( + format!("SELECT current_download FROM {}", list_id).as_str(), + )?; let link_iter = stmt.query_map([], |row| row.get::(0))?; for link in link_iter { @@ -521,8 +562,9 @@ pub fn lists_get(config: &Cfg, list_id: &str) -> MLE { modloader: Modloader::Fabric, download_folder: String::new(), }; - let mut stmt = connection - .prepare("SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?")?; + let mut stmt = connection.prepare( + "SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?", + )?; let list_iter = stmt.query_map([&list_id], |row| { Ok(vec![ @@ -595,7 +637,8 @@ pub fn config_get_current_list(config: &Cfg) -> MLE { let connection = Connection::open(data).unwrap(); let mut list_id = String::new(); - let mut stmt = connection.prepare("SELECT value FROM user_config WHERE id = 'current_list'")?; + let mut stmt = connection + .prepare("SELECT value FROM user_config WHERE id = 'current_list'")?; let list_iter = stmt.query_map([], |row| row.get::(0))?; for list in list_iter { @@ -630,7 +673,9 @@ pub fn s_userlist_update_download( Ok(()) } -pub fn s_config_create_version(config: &Cfg) -> Result<(), Box> { +pub fn s_config_create_version( + config: &Cfg, +) -> Result<(), Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -655,12 +700,15 @@ pub fn s_config_update_version( Ok(()) } -pub fn s_config_get_version(config: &Cfg) -> Result> { +pub fn s_config_get_version( + config: &Cfg, +) -> Result> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut version: String = String::new(); - let mut stmt = connection.prepare("SELECT value FROM user_config WHERE id = 'db_version'")?; + let mut stmt = connection + .prepare("SELECT value FROM user_config WHERE id = 'db_version'")?; let ver_iter = stmt.query_map([], |row| row.get::(0))?; for ver in ver_iter { -- cgit v1.2.3