From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/db.rs | 423 +++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 292 insertions(+), 131 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 2c48cab..09d54c2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,17 +2,21 @@ use std::io::{Error, ErrorKind}; use rusqlite::Connection; -use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}}; +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 connection = Connection::open(data)?; connection.execute( "INSERT INTO mods (id, slug, title) VALUES (?1, ?2, ?3)", - [id, slug, name.replace('\'', "").as_str()] + [id, slug, name.replace('\'', "").as_str()], )?; Ok(()) @@ -21,13 +25,11 @@ 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 connection = Connection::open(data).unwrap(); - + let mut mods: Vec = Vec::new(); let mut stmt = connection.prepare("SELECT id FROM mods")?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { mods.push(id?); @@ -49,36 +51,33 @@ 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 connection = Connection::open(data)?; - + let mut mod_id = String::new(); //get from slug let mut stmt = connection.prepare("SELECT id FROM mods WHERE slug = ?")?; - let id_iter = stmt.query_map([slug], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([slug], |row| row.get::(0))?; for id in id_iter { mod_id = id?; - }; + } //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 id_iter = stmt.query_map([slug], |row| row.get::(0))?; for id in id_iter { mod_id = id?; - }; + } } - if mod_id.is_empty() { return Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")) }; + if mod_id.is_empty() { + return Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")); + }; Ok(mod_id) } @@ -91,17 +90,23 @@ pub struct ModInfo { 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_info: Option = None; 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)?, row.get::(1)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + ]) })?; for info in name_iter { let i = info?; - mod_info = Some(ModInfo { title: String::from(&i[0]), slug: String::from(&i[1]) }); - }; + mod_info = Some(ModInfo { + title: String::from(&i[0]), + slug: String::from(&i[1]), + }); + } match mod_info.is_none() { true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")), @@ -110,7 +115,6 @@ 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()); @@ -131,27 +135,42 @@ 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)?, row.get::(1)?, row.get::(2)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + row.get::(2)?, + ]) })?; for ver in id_iter { let version = ver?; - println!("\t({}) Get versions from the database", String::from(&version[2])); + println!( + "\t({}) Get versions from the database", + String::from(&version[2]) + ); //println!("Found versions {} for mod {}", version[1], version[0]); - versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]) }) - }; + versionmaps.push(DBModlistVersions { + mod_id: String::from(&version[0]), + versions: String::from(&version[1]), + }) + } match versionmaps.is_empty() { true => Err(MLError::new(ErrorType::DBError, "MODS_MODS_NOT_FOUND")), @@ -160,16 +179,37 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE, current_link: &str, set_version: bool) -> MLE<()> { +pub fn userlist_insert( + config: Cfg, + list_id: &str, + mod_id: &str, + current_version: &str, + applicable_versions: Vec, + current_link: &str, + set_version: bool, +) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - + let sv = match set_version { true => "1", false => "0", }; - - connection.execute(format!("INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", list_id).as_str(), [mod_id, current_version, applicable_versions.join("|").as_str(), current_link, sv])?; + + connection.execute( + format!( + "INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", + list_id + ) + .as_str(), + [ + mod_id, + current_version, + applicable_versions.join("|").as_str(), + current_link, + sv, + ], + )?; Ok(()) } @@ -180,14 +220,12 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { let mut mod_ids: Vec = Vec::new(); let mut stmt = connection.prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { //println!("Found id {:?}", id.as_ref().unwrap()); mod_ids.push(id?) - }; + } match mod_ids.is_empty() { true => Err(MLError::new(ErrorType::DBError, "NO_MODS")), @@ -199,24 +237,34 @@ pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute(format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), [mod_id])?; + connection.execute( + format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), + [mod_id], + )?; Ok(()) } - -pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> MLE { +pub fn userlist_get_applicable_versions( + config: Cfg, + list_id: String, + mod_id: String, +) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); - let mut stmt = connection.prepare(format!("SELECT applicable_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 applicable_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?; - }; + } match version.is_empty() { true => Err(MLError::new(ErrorType::DBError, "GAV_MOD_NOT_FOUND")), @@ -224,22 +272,31 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St } } -pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> MLE> { +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 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)?, row.get::(1)?]) + 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(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); }; + if versions.is_empty() { + return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); + }; Ok(versions) } @@ -249,14 +306,13 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> 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?; - }; + } match version.is_empty() { true => Err(MLError::new(ErrorType::DBError, "GCV_MOD_NOT_FOUND")), @@ -264,63 +320,88 @@ 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) -> Result, Box> { +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 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 id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + 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 { versions.push(id?); - }; + } - if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + if versions.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_MODS_ON_LIST", + ))); + }; Ok(versions) } -pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result, Box> { +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 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)?, row.get::(1)?]) + 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"))); }; + if versions.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_MODS_ON_LIST", + ))); + }; 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 = devdir(format!("{}/data.db", config.data).as_str()); 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?; - }; + } Ok(set_version) } -pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> MLE<()> { +pub fn userlist_change_versions( + config: Cfg, + list_id: String, + current_version: String, + versions: String, + link: String, + mod_id: String, +) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -328,33 +409,45 @@ pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: S Ok(()) } -pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_version: String, mod_id: String) -> MLE<()> { +pub fn userlist_add_disabled_versions( + config: Cfg, + list_id: String, + disabled_version: String, + mod_id: String, +) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - - 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" { + + 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), }; - - connection.execute(format!("UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", list_id).as_str(), [disabled_versions, mod_id])?; + + connection.execute( + format!( + "UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", + list_id + ) + .as_str(), + [disabled_versions, mod_id], + )?; Ok(()) } -pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: String) -> MLE { +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 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?; - }; + } match version.is_empty() { true => Err(MLError::new(ErrorType::DBError, "GDV_MOD_NOT_FOUND")), @@ -362,36 +455,57 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin } } -pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result, Box> { +pub fn userlist_get_all_downloads( + config: Cfg, + list_id: String, +) -> Result, Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); 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 link_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + 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 { let l = link?; println!("Found link {}", String::from(&l)); links.push(l) - }; + } - if links.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + if links.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_MODS_ON_LIST", + ))); + }; Ok(links) } //lists ///Inserts into lists table and creates new table -pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> MLE<()> { +pub fn lists_insert( + config: Cfg, + id: String, + mc_version: String, + mod_loader: Modloader, + download_folder: String, +) -> MLE<()> { println!("Creating list {}", id); let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id.clone(), mc_version, mod_loader.to_string(), download_folder])?; + connection.execute( + "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", + [ + id.clone(), + mc_version, + mod_loader.to_string(), + download_folder, + ], + )?; connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?; Ok(()) @@ -410,20 +524,37 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - let mut list = List { id: String::new(), mc_version: String::new(), modloader: Modloader::Fabric, download_folder: String::new() }; - let mut stmt = connection.prepare("SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?")?; + let mut list = List { + id: String::new(), + mc_version: String::new(), + modloader: Modloader::Fabric, + download_folder: String::new(), + }; + 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![row.get::(0)?, row.get::(1)?, row.get::(2)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + row.get::(2)?, + ]) })?; for l in list_iter { let li = l?; - list = List { id: String::from(&list_id), mc_version: String::from(&li[0]), modloader: Modloader::from(&li[1])?, download_folder: String::from(&li[2]) }; - }; + list = List { + id: String::from(&list_id), + mc_version: String::from(&li[0]), + modloader: Modloader::from(&li[1])?, + download_folder: String::from(&li[2]), + }; + } + + if list.id.is_empty() { + return Err(MLError::new(ErrorType::DBError, "LIST_NOT_FOUND")); + } - if list.id.is_empty() { return Err(MLError::new(ErrorType::DBError, "LIST_NOT_FOUND")); } - Ok(list) } @@ -431,23 +562,24 @@ pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - connection.execute("UPDATE lists SET mc_version = ? WHERE id = ?", [version, list_id])?; + connection.execute( + "UPDATE lists SET mc_version = ? WHERE id = ?", + [version, list_id], + )?; Ok(()) } pub fn lists_get_all_ids(config: Cfg) -> MLE> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - + let mut list_ids: Vec = Vec::new(); let mut stmt = connection.prepare("SELECT id FROM lists")?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { list_ids.push(id?) - }; + } match list_ids.is_empty() { true => Err(MLError::new(ErrorType::DBError, "NO_LISTS")), @@ -460,35 +592,50 @@ pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute("UPDATE user_config SET value = ? WHERE id = 'current_list'", [id])?; + connection.execute( + "UPDATE user_config SET value = ? WHERE id = 'current_list'", + [id], + )?; Ok(()) } pub fn config_get_current_list(config: Cfg) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); 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 list_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let list_iter = stmt.query_map([], |row| row.get::(0))?; for list in list_iter { list_id = list?; - }; + } + + if list_id.is_empty() { + return Err(MLError::new(ErrorType::DBError, "NO_CURRENT_LIST")); + } - if list_id.is_empty() { return Err(MLError::new(ErrorType::DBError, "NO_CURRENT_LIST")); } - Ok(list_id) } //SETUP(UPDATES) -pub fn s_userlist_update_download(config: Cfg, list_id: String, mod_id: String, link: String) -> Result<(), Box> { +pub fn s_userlist_update_download( + config: Cfg, + list_id: String, + mod_id: String, + link: String, +) -> Result<(), Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute(format!("UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", list_id).as_str(), [link, mod_id])?; + connection.execute( + format!( + "UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", + list_id + ) + .as_str(), + [link, mod_id], + )?; Ok(()) } @@ -496,7 +643,10 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box Result<(), Box Result> { let data = devdir(format!("{}/data.db", config.data).as_str()); 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 ver_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let ver_iter = stmt.query_map([], |row| row.get::(0))?; for ver in ver_iter { version = ver?; - }; + } - if version.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_DBVERSION"))); }; + if version.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_DBVERSION", + ))); + }; Ok(version) } -pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: String, default: Option) -> Result<(), Box> { +pub fn s_insert_column( + config: Cfg, + table: String, + column: String, + c_type: String, + default: Option, +) -> Result<(), Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); - + if default.is_some() { sql = format!("{} DEFAULT {}", sql, default.unwrap()); } @@ -541,7 +703,6 @@ pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: Strin } pub fn db_setup(config: Cfg) -> MLE<()> { - println!("Initiating database"); let data = devdir(format!("{}/data.db", config.data).as_str()); @@ -554,6 +715,6 @@ pub fn db_setup(config: Cfg) -> MLE<()> { INSERT INTO 'user_config' VALUES ( 'db_version', '0.5' ); INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", )?; - + Ok(()) } -- cgit v1.2.3