From 3e65975227baa511f570e8223fccda5607cf905e Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 23 Apr 2023 21:47:37 +0200 Subject: added config argument, remove devdir --- src/db.rs | 65 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 09d54c2..2ffcff5 100644 --- a/src/db.rs +++ b/src/db.rs @@ -4,14 +4,13 @@ use rusqlite::Connection; use crate::{ config::Cfg, - devdir, error::{ErrorType, MLError, MLE}, List, Modloader, }; //MODS pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -23,7 +22,7 @@ pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { } pub fn mods_get_all_ids(config: Cfg) -> Result, Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut mods: Vec = Vec::new(); @@ -53,7 +52,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box MLE { //TODO check if "slug" is id - let data = devdir(format!("{}/data.db", data).as_str()); + let data = format!("{}/data.db", data); let connection = Connection::open(data)?; let mut mod_id = String::new(); @@ -88,7 +87,7 @@ pub struct ModInfo { } pub fn mods_get_info(config: Cfg, id: &str) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut mod_info: Option = None; @@ -117,7 +116,7 @@ pub fn mods_get_info(config: Cfg, id: &str) -> MLE { pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { println!("Removing mod {} from database", id); - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute("DELETE FROM mods WHERE id = ?", [id])?; @@ -132,7 +131,7 @@ pub struct DBModlistVersions { } pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; if mods.is_empty() { @@ -188,7 +187,7 @@ pub fn userlist_insert( current_link: &str, set_version: bool, ) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let sv = match set_version { @@ -215,7 +214,7 @@ pub fn userlist_insert( } pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut mod_ids: Vec = Vec::new(); @@ -234,7 +233,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { } pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -249,7 +248,7 @@ pub fn userlist_get_applicable_versions( list_id: String, mod_id: String, ) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); @@ -276,7 +275,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( config: Cfg, list_id: String, ) -> MLE> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut versions: Vec<(String, String)> = Vec::new(); @@ -302,7 +301,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( } pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); @@ -324,7 +323,7 @@ pub fn userlist_get_all_current_version_ids( config: Cfg, list_id: String, ) -> Result, Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut versions: Vec = Vec::new(); @@ -350,7 +349,7 @@ pub fn userlist_get_all_current_versions_with_mods( config: Cfg, list_id: String, ) -> Result, Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut versions: Vec<(String, String)> = Vec::new(); @@ -379,7 +378,7 @@ pub fn userlist_get_all_current_versions_with_mods( } pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut set_version: bool = false; @@ -402,7 +401,7 @@ pub fn userlist_change_versions( link: String, mod_id: String, ) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute(format!("UPDATE {} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4", list_id).as_str(), [current_version, versions, link, mod_id])?; @@ -415,7 +414,7 @@ pub fn userlist_add_disabled_versions( disabled_version: String, mod_id: String, ) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let currently_disabled_versions = @@ -437,7 +436,7 @@ pub fn userlist_add_disabled_versions( } pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: String) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); @@ -459,7 +458,7 @@ pub fn userlist_get_all_downloads( config: Cfg, list_id: String, ) -> Result, Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut links: Vec = Vec::new(); @@ -494,7 +493,7 @@ pub fn lists_insert( ) -> MLE<()> { println!("Creating list {}", id); - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -512,7 +511,7 @@ pub fn lists_insert( } pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; @@ -521,7 +520,7 @@ pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { } pub fn lists_get(config: Cfg, list_id: String) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut list = List { @@ -559,7 +558,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE { } pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); connection.execute( @@ -570,7 +569,7 @@ pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { } pub fn lists_get_all_ids(config: Cfg) -> MLE> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut list_ids: Vec = Vec::new(); @@ -589,7 +588,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE> { //config pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -600,7 +599,7 @@ pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { } pub fn config_get_current_list(config: Cfg) -> MLE { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); let mut list_id = String::new(); @@ -625,7 +624,7 @@ pub fn s_userlist_update_download( mod_id: String, link: String, ) -> Result<(), Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -640,7 +639,7 @@ pub fn s_userlist_update_download( } pub fn s_config_create_version(config: Cfg) -> Result<(), Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -651,7 +650,7 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box Result<(), Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute( @@ -662,7 +661,7 @@ pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box Result> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut version: String = String::new(); @@ -689,7 +688,7 @@ pub fn s_insert_column( c_type: String, default: Option, ) -> Result<(), Box> { - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); @@ -705,7 +704,7 @@ pub fn s_insert_column( pub fn db_setup(config: Cfg) -> MLE<()> { println!("Initiating database"); - let data = devdir(format!("{}/data.db", config.data).as_str()); + let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; connection.execute_batch( -- cgit v1.2.3