From ea50af892c4268ae06f6df40ee435eadd076228d Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 6 Nov 2022 23:06:54 +0100 Subject: halfswitch to rusqlite; db tests --- src/commands/list.rs | 10 +++++----- src/commands/modification.rs | 28 +++++++++++++++++----------- src/commands/setup.rs | 6 +++--- src/commands/update.rs | 4 ++-- 4 files changed, 27 insertions(+), 21 deletions(-) (limited to 'src/commands') diff --git a/src/commands/list.rs b/src/commands/list.rs index 3dfe1ad..ffa5926 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,6 +1,6 @@ use std::io::{Error, ErrorKind}; -use crate::{db::{insert_list, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; +use crate::{db::{lists_insert, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; #[derive(Clone)] pub struct List { @@ -52,8 +52,8 @@ fn add(config: Cfg, args: Vec) -> Result<(), Box> "fabric" => Modloader::Fabric, _ => return Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_MODLOADER"))) }; - match insert_list(config, id, mc_version, mod_loader) { - Err(err) => { Err(Box::new(err)) }, + match lists_insert(config, id, mc_version, mod_loader) { + Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, Ok(()) => Ok(()), } }, @@ -69,7 +69,7 @@ fn change(config: Cfg, args: Vec) -> Result<(), Box { Err(Box::new(err)) }, + Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, Ok(()) => Ok(()), } }, @@ -82,7 +82,7 @@ fn remove(config: Cfg, args: Vec) -> Result<(), Box { match remove_list(config, String::from(&args[0])) { - Err(err) => { Err(Box::new(err)) }, + Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, Ok(()) => Ok(()), } }, diff --git a/src/commands/modification.rs b/src/commands/modification.rs index e877a63..7836735 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,6 +1,6 @@ use std::io::{Error, ErrorKind}; -use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{insert_mod, remove_mod_from_list, get_mod_id, insert_mod_in_list, get_mods, get_mods_from_list}, input::Input, get_current_list}; +use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::Input, get_current_list}; pub async fn modification(config: Cfg, args: Option>) -> Result<(), Box> { @@ -40,31 +40,37 @@ async fn add(config: Cfg, args: Vec) -> Result<(), Box = Vec::new(); + for ver in available_versions { + available_versions_vec.push(ver.id); + } //add to current list and mod table - match get_mods_from_list(config.clone(), current_list.clone()) { + match userlist_get_all_ids(config.clone(), current_list.clone().id) { Ok(mods) => { dbg!(&mods); if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } else { - insert_mod_in_list(config.clone(), current_list.clone(), String::from(&project.id), current_version.id, available_versions, file)?; + userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?; } }, - Err(..) => insert_mod_in_list(config.clone(), current_list, String::from(&project.id), current_version.id, available_versions, file)?, + Err(..) => userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?, }; - match get_mods(config.clone()) { + match mods_get_all_ids(config.clone()) { Ok(mods) => { dbg!(&mods); if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) } else { - insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; + mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; } }, - Err(..) => insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?, + Err(..) => { + mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; + }, }; - Ok(()) } @@ -72,11 +78,11 @@ fn remove(config: Cfg, args: Vec) -> Result<(), Box { Err(Box::new(err)) }, + match userlist_remove(config, current_list.id, mod_id) { + Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, Ok(()) => Ok(()), } } diff --git a/src/commands/setup.rs b/src/commands/setup.rs index 0223a21..0940959 100644 --- a/src/commands/setup.rs +++ b/src/commands/setup.rs @@ -1,6 +1,6 @@ use std::{fs::File, path::Path, io::{Error, ErrorKind}}; -use crate::{config::Cfg, db::{db_setup, get_dbversion, create_dbversion, insert_column, get_lists, get_list, get_current_versions, insert_dl_link}, modrinth::get_raw_versions}; +use crate::{config::Cfg, db::{db_setup, user_dbversion, create_dbversion, insert_column, get_lists, get_list, get_current_versions, insert_dl_link}, modrinth::get_raw_versions}; pub async fn setup(config: Cfg) -> Result<(), Box> { @@ -10,7 +10,7 @@ pub async fn setup(config: Cfg) -> Result<(), Box> { return create(config, db_file); } - match get_dbversion(config.clone()) { + match user_dbversion(config.clone()) { Ok(ver) => { match ver.as_str() { _ => return Err(Box::new(Error::new(ErrorKind::Other, "UNKNOWN_VERSION"))) @@ -33,7 +33,7 @@ async fn to_02(config: Cfg) -> Result<(), Box> { for list in lists { println!("Updating {}", list); - insert_column(config.clone(), String::from(&list), String::from("current_download"), sqlite::Type::String)?; + insert_column(config.clone(), String::from(&list), String::from("current_download"), String::new())?; let full_list = get_list(config.clone(), String::from(&list))?; diff --git a/src/commands/update.rs b/src/commands/update.rs index 284d289..d278a78 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -4,13 +4,13 @@ use reqwest::Client; use futures_util::StreamExt; -use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{get_mods_from_list, get_versions, get_list_version, change_list_versions}, List}; +use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, get_versions, get_list_version, change_list_versions}, List}; pub async fn update(config: Cfg) -> Result<(), Box> { let current_list = get_current_list(config.clone())?; - let mods = get_mods_from_list(config.clone(), current_list.clone())?; + let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; let mut versions = get_versions(config.clone(), mods.clone())?; versions.sort_by_key(|ver| ver.mod_id.clone()); -- cgit v1.2.3