summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-01-22 22:34:17 +0100
committerfxqnlr <[email protected]>2023-01-22 22:34:17 +0100
commit1890d59428dfcca861ea1b7820411d80cc60d713 (patch)
tree559a41a814a33a72ccab3640a6c81d10451f1683 /src/db.rs
parentf7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 (diff)
downloadmodlist-1890d59428dfcca861ea1b7820411d80cc60d713.tar
modlist-1890d59428dfcca861ea1b7820411d80cc60d713.tar.gz
modlist-1890d59428dfcca861ea1b7820411d80cc60d713.zip
Added list version cmd, fixed some todos
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/db.rs b/src/db.rs
index 119b2a5..f47bda6 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -5,7 +5,7 @@ use rusqlite::Connection;
5use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}}; 5use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}};
6 6
7//mods 7//mods
8pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { 8pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec<String>) -> MLE<()> {
9 9
10 println!("Inserting mod {}({}) into database", name, id); 10 println!("Inserting mod {}({}) into database", name, id);
11 11
@@ -41,7 +41,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::
41 } 41 }
42} 42}
43 43
44pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::error::Error>> { 44pub fn mods_get_id(config: Cfg, name: String) -> MLE<String> {
45 let data = devdir(format!("{}/data.db", config.data).as_str()); 45 let data = devdir(format!("{}/data.db", config.data).as_str());
46 let connection = Connection::open(data)?; 46 let connection = Connection::open(data)?;
47 47
@@ -56,12 +56,12 @@ pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::err
56 }; 56 };
57 57
58 match mod_id.is_empty() { 58 match mod_id.is_empty() {
59 true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), 59 true => Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")),
60 false => Ok(mod_id), 60 false => Ok(mod_id),
61 } 61 }
62} 62}
63 63
64pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> { 64pub fn mods_get_name(config: Cfg, id: &str) -> MLE<String> {
65 let data = devdir(format!("{}/data.db", config.data).as_str()); 65 let data = devdir(format!("{}/data.db", config.data).as_str());
66 let connection = Connection::open(data)?; 66 let connection = Connection::open(data)?;
67 67
@@ -76,14 +76,14 @@ pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::err
76 }; 76 };
77 77
78 match mod_name.is_empty() { 78 match mod_name.is_empty() {
79 true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), 79 true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")),
80 false => Ok(mod_name), 80 false => Ok(mod_name),
81 } 81 }
82} 82}
83 83
84pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> MLE<()> { 84pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> MLE<()> {
85 85
86 println!("Updating versions for {} with \n {}", mod_id, versions); 86 //println!("Updating versions for {} with \n {}", mod_id, versions);
87 87
88 let data = devdir(format!("{}/data.db", config.data).as_str()); 88 let data = devdir(format!("{}/data.db", config.data).as_str());
89 let connection = Connection::open(data)?; 89 let connection = Connection::open(data)?;
@@ -92,7 +92,7 @@ pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> ML
92 Ok(()) 92 Ok(())
93} 93}
94 94
95pub fn mods_remove(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { 95pub fn mods_remove(config: Cfg, id: String) -> MLE<()> {
96 96
97 println!("Removing mod {} from database", id); 97 println!("Removing mod {} from database", id);
98 98
@@ -131,7 +131,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer
131 131
132 for ver in id_iter { 132 for ver in id_iter {
133 let version = ver?; 133 let version = ver?;
134 println!("Getting versions for {} from the database", String::from(&version[2])); 134 println!("\t({}) Get versions from the database", String::from(&version[2]));
135 //println!("Found versions {} for mod {}", version[1], version[0]); 135 //println!("Found versions {} for mod {}", version[1], version[0]);
136 versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]) }) 136 versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]) })
137 }; 137 };
@@ -143,7 +143,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer
143} 143}
144 144
145//userlist 145//userlist
146pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_version: String, applicable_versions: Vec<String>, current_link: String) -> Result<(), Box<dyn std::error::Error>> { 146pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_version: String, applicable_versions: Vec<String>, current_link: String) -> MLE<()> {
147 println!("Inserting {} into current list({})", mod_id, list_id); 147 println!("Inserting {} into current list({})", mod_id, list_id);
148 148
149 let data = devdir(format!("{}/data.db", config.data).as_str()); 149 let data = devdir(format!("{}/data.db", config.data).as_str());
@@ -201,7 +201,7 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St
201 }; 201 };
202 202
203 match version.is_empty() { 203 match version.is_empty() {
204 true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), 204 true => Err(MLError::new(ErrorType::DBError, "GAV_MOD_NOT_FOUND")),
205 false => Ok(version), 205 false => Ok(version),
206 } 206 }
207} 207}
@@ -241,7 +241,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String
241 }; 241 };
242 242
243 match version.is_empty() { 243 match version.is_empty() {
244 true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), 244 true => Err(MLError::new(ErrorType::DBError, "GCV_MOD_NOT_FOUND")),
245 false => Ok(version), 245 false => Ok(version),
246 } 246 }
247} 247}
@@ -285,7 +285,7 @@ pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String)
285 Ok(versions) 285 Ok(versions)
286} 286}
287 287
288pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { 288pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> MLE<()> {
289 let data = devdir(format!("{}/data.db", config.data).as_str()); 289 let data = devdir(format!("{}/data.db", config.data).as_str());
290 let connection = Connection::open(data)?; 290 let connection = Connection::open(data)?;
291 291
@@ -322,7 +322,7 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin
322 }; 322 };
323 323
324 match version.is_empty() { 324 match version.is_empty() {
325 true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), 325 true => Err(MLError::new(ErrorType::DBError, "GDV_MOD_NOT_FOUND")),
326 false => Ok(version), 326 false => Ok(version),
327 } 327 }
328} 328}