summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs216
1 files changed, 126 insertions, 90 deletions
diff --git a/src/db.rs b/src/db.rs
index 8fd21b1..49db2fd 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -9,7 +9,7 @@ use crate::{
9}; 9};
10 10
11//MODS 11//MODS
12pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { 12pub fn mods_insert(config: &Cfg, id: &str, slug: &str, name: &str) -> MLE<()> {
13 let data = format!("{}/data.db", config.data); 13 let data = format!("{}/data.db", config.data);
14 let connection = Connection::open(data)?; 14 let connection = Connection::open(data)?;
15 15
@@ -21,7 +21,9 @@ pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> {
21 Ok(()) 21 Ok(())
22} 22}
23 23
24pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { 24pub fn mods_get_all_ids(
25 config: &Cfg,
26) -> Result<Vec<String>, Box<dyn std::error::Error>> {
25 let data = format!("{}/data.db", config.data); 27 let data = format!("{}/data.db", config.data);
26 let connection = Connection::open(data).unwrap(); 28 let connection = Connection::open(data).unwrap();
27 29
@@ -64,8 +66,10 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> {
64 } 66 }
65 //get from id if no slug found 67 //get from id if no slug found
66 if mod_id.is_empty() { 68 if mod_id.is_empty() {
67 let mut stmt = connection.prepare("SELECT id FROM mods WHERE id = ?")?; 69 let mut stmt =
68 let id_iter = stmt.query_map([slug], |row| row.get::<usize, String>(0))?; 70 connection.prepare("SELECT id FROM mods WHERE id = ?")?;
71 let id_iter =
72 stmt.query_map([slug], |row| row.get::<usize, String>(0))?;
69 73
70 for id in id_iter { 74 for id in id_iter {
71 mod_id = id?; 75 mod_id = id?;
@@ -73,8 +77,10 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> {
73 } 77 }
74 //get from title if no id found from slug 78 //get from title if no id found from slug
75 if mod_id.is_empty() { 79 if mod_id.is_empty() {
76 let mut stmt = connection.prepare("SELECT id FROM mods WHERE title = ?")?; 80 let mut stmt =
77 let id_iter = stmt.query_map([slug], |row| row.get::<usize, String>(0))?; 81 connection.prepare("SELECT id FROM mods WHERE title = ?")?;
82 let id_iter =
83 stmt.query_map([slug], |row| row.get::<usize, String>(0))?;
78 84
79 for id in id_iter { 85 for id in id_iter {
80 mod_id = id?; 86 mod_id = id?;
@@ -93,12 +99,13 @@ pub struct ModInfo {
93 pub title: String, 99 pub title: String,
94} 100}
95 101
96pub fn mods_get_info(config: Cfg, id: &str) -> MLE<ModInfo> { 102pub fn mods_get_info(config: &Cfg, id: &str) -> MLE<ModInfo> {
97 let data = format!("{}/data.db", config.data); 103 let data = format!("{}/data.db", config.data);
98 let connection = Connection::open(data)?; 104 let connection = Connection::open(data)?;
99 105
100 let mut mod_info: Option<ModInfo> = None; 106 let mut mod_info: Option<ModInfo> = None;
101 let mut stmt = connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?; 107 let mut stmt =
108 connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?;
102 let name_iter = stmt.query_map([id], |row| { 109 let name_iter = stmt.query_map([id], |row| {
103 Ok(vec![ 110 Ok(vec![
104 row.get::<usize, String>(0)?, 111 row.get::<usize, String>(0)?,
@@ -120,9 +127,7 @@ pub fn mods_get_info(config: Cfg, id: &str) -> MLE<ModInfo> {
120 } 127 }
121} 128}
122 129
123pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { 130pub fn mods_remove(config: &Cfg, id: &str) -> MLE<()> {
124 println!("Removing mod {} from database", id);
125
126 let data = format!("{}/data.db", config.data); 131 let data = format!("{}/data.db", config.data);
127 let connection = Connection::open(data)?; 132 let connection = Connection::open(data)?;
128 133
@@ -137,7 +142,10 @@ pub struct DBModlistVersions {
137 pub versions: String, 142 pub versions: String,
138} 143}
139 144
140pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVersions>> { 145pub fn mods_get_versions(
146 config: &Cfg,
147 mods: Vec<String>,
148) -> MLE<Vec<DBModlistVersions>> {
141 let data = format!("{}/data.db", config.data); 149 let data = format!("{}/data.db", config.data);
142 let connection = Connection::open(data)?; 150 let connection = Connection::open(data)?;
143 151
@@ -155,8 +163,9 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer
155 } 163 }
156 164
157 let mut versionmaps: Vec<DBModlistVersions> = Vec::new(); 165 let mut versionmaps: Vec<DBModlistVersions> = Vec::new();
158 let mut stmt = connection 166 let mut stmt = connection.prepare(
159 .prepare(format!("SELECT id, versions, title FROM mods {}", wherestr).as_str())?; 167 format!("SELECT id, versions, title FROM mods {}", wherestr).as_str(),
168 )?;
160 let id_iter = stmt.query_map([], |row| { 169 let id_iter = stmt.query_map([], |row| {
161 Ok(vec![ 170 Ok(vec![
162 row.get::<usize, String>(0)?, 171 row.get::<usize, String>(0)?,
@@ -167,11 +176,6 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer
167 176
168 for ver in id_iter { 177 for ver in id_iter {
169 let version = ver?; 178 let version = ver?;
170 println!(
171 "\t({}) Get versions from the database",
172 String::from(&version[2])
173 );
174 //println!("Found versions {} for mod {}", version[1], version[0]);
175 versionmaps.push(DBModlistVersions { 179 versionmaps.push(DBModlistVersions {
176 mod_id: String::from(&version[0]), 180 mod_id: String::from(&version[0]),
177 versions: String::from(&version[1]), 181 versions: String::from(&version[1]),
@@ -186,7 +190,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer
186 190
187//userlist 191//userlist
188pub fn userlist_insert( 192pub fn userlist_insert(
189 config: Cfg, 193 config: &Cfg,
190 list_id: &str, 194 list_id: &str,
191 mod_id: &str, 195 mod_id: &str,
192 current_version: &str, 196 current_version: &str,
@@ -220,26 +224,29 @@ pub fn userlist_insert(
220 Ok(()) 224 Ok(())
221} 225}
222 226
223pub fn userlist_get_all_ids(config: Cfg, list_id: &str) -> MLE<Vec<String>> { 227pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE<Vec<String>> {
224 let data = format!("{}/data.db", config.data); 228 let data = format!("{}/data.db", config.data);
225 let connection = Connection::open(data).unwrap(); 229 let connection = Connection::open(data).unwrap();
226 230
227 let mut mod_ids: Vec<String> = Vec::new(); 231 let mut mod_ids: Vec<String> = Vec::new();
228 let mut stmt = connection.prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; 232 let mut stmt = connection
233 .prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?;
229 let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; 234 let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?;
230 235
231 for id in id_iter { 236 for id in id_iter {
232 //println!("Found id {:?}", id.as_ref().unwrap());
233 mod_ids.push(id?) 237 mod_ids.push(id?)
234 } 238 }
235 239
236 match mod_ids.is_empty() { 240 match mod_ids.is_empty() {
237 true => Err(MLError::new(ErrorType::DBError, "NO_MODS_USERLIST")), 241 true => Err(MLError::new(
242 ErrorType::DBError,
243 &format!("NO_MODS_USERLIST{}", list_id),
244 )),
238 false => Ok(mod_ids), 245 false => Ok(mod_ids),
239 } 246 }
240} 247}
241 248
242pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { 249pub fn userlist_remove(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<()> {
243 let data = format!("{}/data.db", config.data); 250 let data = format!("{}/data.db", config.data);
244 let connection = Connection::open(data)?; 251 let connection = Connection::open(data)?;
245 252
@@ -251,7 +258,7 @@ pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> {
251} 258}
252 259
253pub fn userlist_get_applicable_versions( 260pub fn userlist_get_applicable_versions(
254 config: Cfg, 261 config: &Cfg,
255 list_id: String, 262 list_id: String,
256 mod_id: String, 263 mod_id: String,
257) -> MLE<String> { 264) -> MLE<String> {
@@ -266,7 +273,8 @@ pub fn userlist_get_applicable_versions(
266 ) 273 )
267 .as_str(), 274 .as_str(),
268 )?; 275 )?;
269 let ver_iter = stmt.query_map([mod_id], |row| row.get::<usize, String>(0))?; 276 let ver_iter =
277 stmt.query_map([mod_id], |row| row.get::<usize, String>(0))?;
270 278
271 for ver in ver_iter { 279 for ver in ver_iter {
272 version = ver?; 280 version = ver?;
@@ -279,15 +287,16 @@ pub fn userlist_get_applicable_versions(
279} 287}
280 288
281pub fn userlist_get_all_applicable_versions_with_mods( 289pub fn userlist_get_all_applicable_versions_with_mods(
282 config: Cfg, 290 config: &Cfg,
283 list_id: String, 291 list_id: String,
284) -> MLE<Vec<(String, String)>> { 292) -> MLE<Vec<(String, String)>> {
285 let data = format!("{}/data.db", config.data); 293 let data = format!("{}/data.db", config.data);
286 let connection = Connection::open(data)?; 294 let connection = Connection::open(data)?;
287 295
288 let mut versions: Vec<(String, String)> = Vec::new(); 296 let mut versions: Vec<(String, String)> = Vec::new();
289 let mut stmt = connection 297 let mut stmt = connection.prepare(
290 .prepare(format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str())?; 298 format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str(),
299 )?;
291 let id_iter = stmt.query_map([], |row| { 300 let id_iter = stmt.query_map([], |row| {
292 Ok(vec![ 301 Ok(vec![
293 row.get::<usize, String>(0)?, 302 row.get::<usize, String>(0)?,
@@ -307,14 +316,21 @@ pub fn userlist_get_all_applicable_versions_with_mods(
307 Ok(versions) 316 Ok(versions)
308} 317}
309 318
310pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE<String> { 319pub fn userlist_get_current_version(
320 config: &Cfg,
321 list_id: &str,
322 mod_id: &str,
323) -> MLE<String> {
311 let data = format!("{}/data.db", config.data); 324 let data = format!("{}/data.db", config.data);
312 let connection = Connection::open(data).unwrap(); 325 let connection = Connection::open(data).unwrap();
313 326
314 let mut version: String = String::new(); 327 let mut version: String = String::new();
315 let mut stmt = connection 328 let mut stmt = connection.prepare(
316 .prepare(format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id).as_str())?; 329 format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id)
317 let ver_iter = stmt.query_map([&mod_id], |row| row.get::<usize, String>(0))?; 330 .as_str(),
331 )?;
332 let ver_iter =
333 stmt.query_map([&mod_id], |row| row.get::<usize, String>(0))?;
318 334
319 for ver in ver_iter { 335 for ver in ver_iter {
320 version = ver?; 336 version = ver?;
@@ -327,15 +343,15 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) ->
327} 343}
328 344
329pub fn userlist_get_all_current_version_ids( 345pub fn userlist_get_all_current_version_ids(
330 config: Cfg, 346 config: &Cfg,
331 list_id: String, 347 list_id: String,
332) -> MLE<Vec<String>> { 348) -> MLE<Vec<String>> {
333 let data = format!("{}/data.db", config.data); 349 let data = format!("{}/data.db", config.data);
334 let connection = Connection::open(data)?; 350 let connection = Connection::open(data)?;
335 351
336 let mut versions: Vec<String> = Vec::new(); 352 let mut versions: Vec<String> = Vec::new();
337 let mut stmt = 353 let mut stmt = connection
338 connection.prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; 354 .prepare(format!("SELECT current_version FROM {}", list_id).as_str())?;
339 let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; 355 let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?;
340 356
341 for id in id_iter { 357 for id in id_iter {
@@ -343,25 +359,23 @@ pub fn userlist_get_all_current_version_ids(
343 } 359 }
344 360
345 if versions.is_empty() { 361 if versions.is_empty() {
346 return Err(MLError::new( 362 return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST"));
347 ErrorType::DBError,
348 "NO_MODS_ON_LIST",
349 ));
350 }; 363 };
351 364
352 Ok(versions) 365 Ok(versions)
353} 366}
354 367
355pub fn userlist_get_all_current_versions_with_mods( 368pub fn userlist_get_all_current_versions_with_mods(
356 config: Cfg, 369 config: &Cfg,
357 list_id: String, 370 list_id: String,
358) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { 371) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> {
359 let data = format!("{}/data.db", config.data); 372 let data = format!("{}/data.db", config.data);
360 let connection = Connection::open(data)?; 373 let connection = Connection::open(data)?;
361 374
362 let mut versions: Vec<(String, String)> = Vec::new(); 375 let mut versions: Vec<(String, String)> = Vec::new();
363 let mut stmt = 376 let mut stmt = connection.prepare(
364 connection.prepare(format!("SELECT mod_id, current_version FROM {}", list_id).as_str())?; 377 format!("SELECT mod_id, current_version FROM {}", list_id).as_str(),
378 )?;
365 let id_iter = stmt.query_map([], |row| { 379 let id_iter = stmt.query_map([], |row| {
366 Ok(vec![ 380 Ok(vec![
367 row.get::<usize, String>(0)?, 381 row.get::<usize, String>(0)?,
@@ -384,14 +398,21 @@ pub fn userlist_get_all_current_versions_with_mods(
384 Ok(versions) 398 Ok(versions)
385} 399}
386 400
387pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE<bool> { 401pub fn userlist_get_set_version(
402 config: &Cfg,
403 list_id: &str,
404 mod_id: &str,
405) -> MLE<bool> {
388 let data = format!("{}/data.db", config.data); 406 let data = format!("{}/data.db", config.data);
389 let connection = Connection::open(data).unwrap(); 407 let connection = Connection::open(data).unwrap();
390 408
391 let mut set_version: bool = false; 409 let mut set_version: bool = false;
392 let mut stmt = connection 410 let mut stmt = connection.prepare(
393 .prepare(format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id).as_str())?; 411 format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id)
394 let ver_iter = stmt.query_map([&mod_id], |row| row.get::<usize, bool>(0))?; 412 .as_str(),
413 )?;
414 let ver_iter =
415 stmt.query_map([&mod_id], |row| row.get::<usize, bool>(0))?;
395 416
396 for ver in ver_iter { 417 for ver in ver_iter {
397 set_version = ver?; 418 set_version = ver?;
@@ -401,7 +422,7 @@ pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE
401} 422}
402 423
403pub fn userlist_change_versions( 424pub fn userlist_change_versions(
404 config: Cfg, 425 config: &Cfg,
405 list_id: String, 426 list_id: String,
406 current_version: String, 427 current_version: String,
407 versions: String, 428 versions: String,
@@ -416,7 +437,7 @@ pub fn userlist_change_versions(
416} 437}
417 438
418pub fn userlist_add_disabled_versions( 439pub fn userlist_add_disabled_versions(
419 config: Cfg, 440 config: &Cfg,
420 list_id: String, 441 list_id: String,
421 disabled_version: String, 442 disabled_version: String,
422 mod_id: String, 443 mod_id: String,
@@ -424,11 +445,16 @@ pub fn userlist_add_disabled_versions(
424 let data = format!("{}/data.db", config.data); 445 let data = format!("{}/data.db", config.data);
425 let connection = Connection::open(data)?; 446 let connection = Connection::open(data)?;
426 447
427 let currently_disabled_versions = 448 let currently_disabled_versions = userlist_get_disabled_versions(
428 userlist_get_disabled_versions(config, String::from(&list_id), String::from(&mod_id))?; 449 config,
450 String::from(&list_id),
451 String::from(&mod_id),
452 )?;
429 let disabled_versions = match currently_disabled_versions == "NONE" { 453 let disabled_versions = match currently_disabled_versions == "NONE" {
430 true => disabled_version, 454 true => disabled_version,
431 false => format!("{}|{}", currently_disabled_versions, disabled_version), 455 false => {
456 format!("{}|{}", currently_disabled_versions, disabled_version)
457 }
432 }; 458 };
433 459
434 connection.execute( 460 connection.execute(
@@ -442,14 +468,21 @@ pub fn userlist_add_disabled_versions(
442 Ok(()) 468 Ok(())
443} 469}
444 470
445pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: String) -> MLE<String> { 471pub fn userlist_get_disabled_versions(
472 config: &Cfg,
473 list_id: String,
474 mod_id: String,
475) -> MLE<String> {
446 let data = format!("{}/data.db", config.data); 476 let data = format!("{}/data.db", config.data);
447 let connection = Connection::open(data).unwrap(); 477 let connection = Connection::open(data).unwrap();
448 478
449 let mut version: String = String::new(); 479 let mut version: String = String::new();
450 let mut stmt = connection 480 let mut stmt = connection.prepare(
451 .prepare(format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id).as_str())?; 481 format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id)
452 let ver_iter = stmt.query_map([mod_id], |row| row.get::<usize, String>(0))?; 482 .as_str(),
483 )?;
484 let ver_iter =
485 stmt.query_map([mod_id], |row| row.get::<usize, String>(0))?;
453 486
454 for ver in ver_iter { 487 for ver in ver_iter {
455 version = ver?; 488 version = ver?;
@@ -462,20 +495,20 @@ pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: Stri
462} 495}
463 496
464pub fn userlist_get_all_downloads( 497pub fn userlist_get_all_downloads(
465 config: Cfg, 498 config: &Cfg,
466 list_id: String, 499 list_id: String,
467) -> Result<Vec<String>, Box<dyn std::error::Error>> { 500) -> Result<Vec<String>, Box<dyn std::error::Error>> {
468 let data = format!("{}/data.db", config.data); 501 let data = format!("{}/data.db", config.data);
469 let connection = Connection::open(data).unwrap(); 502 let connection = Connection::open(data).unwrap();
470 503
471 let mut links: Vec<String> = Vec::new(); 504 let mut links: Vec<String> = Vec::new();
472 let mut stmt = 505 let mut stmt = connection.prepare(
473 connection.prepare(format!("SELECT current_download FROM {}", list_id).as_str())?; 506 format!("SELECT current_download FROM {}", list_id).as_str(),
507 )?;
474 let link_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; 508 let link_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?;
475 509
476 for link in link_iter { 510 for link in link_iter {
477 let l = link?; 511 let l = link?;
478 println!("Found link {}", String::from(&l));
479 links.push(l) 512 links.push(l)
480 } 513 }
481 514
@@ -492,32 +525,25 @@ pub fn userlist_get_all_downloads(
492//lists 525//lists
493///Inserts into lists table and creates new table 526///Inserts into lists table and creates new table
494pub fn lists_insert( 527pub fn lists_insert(
495 config: Cfg, 528 config: &Cfg,
496 id: String, 529 id: &str,
497 mc_version: String, 530 mc_version: &str,
498 mod_loader: Modloader, 531 mod_loader: &Modloader,
499 download_folder: String, 532 download_folder: &str,
500) -> MLE<()> { 533) -> MLE<()> {
501 println!("Creating list {}", id);
502
503 let data = format!("{}/data.db", config.data); 534 let data = format!("{}/data.db", config.data);
504 let connection = Connection::open(data)?; 535 let connection = Connection::open(data)?;
505 536
506 connection.execute( 537 connection.execute(
507 "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", 538 "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)",
508 [ 539 [id, mc_version, &mod_loader.to_string(), download_folder],
509 id.clone(),
510 mc_version,
511 mod_loader.to_string(),
512 download_folder,
513 ],
514 )?; 540 )?;
515 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(), [])?; 541 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(), [])?;
516 542
517 Ok(()) 543 Ok(())
518} 544}
519 545
520pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { 546pub fn lists_remove(config: &Cfg, id: &str) -> MLE<()> {
521 let data = format!("{}/data.db", config.data); 547 let data = format!("{}/data.db", config.data);
522 let connection = Connection::open(data)?; 548 let connection = Connection::open(data)?;
523 549
@@ -526,7 +552,7 @@ pub fn lists_remove(config: Cfg, id: String) -> MLE<()> {
526 Ok(()) 552 Ok(())
527} 553}
528 554
529pub fn lists_get(config: Cfg, list_id: String) -> MLE<List> { 555pub fn lists_get(config: &Cfg, list_id: &str) -> MLE<List> {
530 let data = format!("{}/data.db", config.data); 556 let data = format!("{}/data.db", config.data);
531 let connection = Connection::open(data).unwrap(); 557 let connection = Connection::open(data).unwrap();
532 558
@@ -536,8 +562,9 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE<List> {
536 modloader: Modloader::Fabric, 562 modloader: Modloader::Fabric,
537 download_folder: String::new(), 563 download_folder: String::new(),
538 }; 564 };
539 let mut stmt = connection 565 let mut stmt = connection.prepare(
540 .prepare("SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?")?; 566 "SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?",
567 )?;
541 568
542 let list_iter = stmt.query_map([&list_id], |row| { 569 let list_iter = stmt.query_map([&list_id], |row| {
543 Ok(vec![ 570 Ok(vec![
@@ -550,7 +577,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE<List> {
550 for l in list_iter { 577 for l in list_iter {
551 let li = l?; 578 let li = l?;
552 list = List { 579 list = List {
553 id: String::from(&list_id), 580 id: list_id.to_string(),
554 mc_version: String::from(&li[0]), 581 mc_version: String::from(&li[0]),
555 modloader: Modloader::from(&li[1])?, 582 modloader: Modloader::from(&li[1])?,
556 download_folder: String::from(&li[2]), 583 download_folder: String::from(&li[2]),
@@ -564,7 +591,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE<List> {
564 Ok(list) 591 Ok(list)
565} 592}
566 593
567pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { 594pub fn lists_version(config: &Cfg, list_id: &str, version: &str) -> MLE<()> {
568 let data = format!("{}/data.db", config.data); 595 let data = format!("{}/data.db", config.data);
569 let connection = Connection::open(data).unwrap(); 596 let connection = Connection::open(data).unwrap();
570 597
@@ -575,7 +602,7 @@ pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> {
575 Ok(()) 602 Ok(())
576} 603}
577 604
578pub fn lists_get_all_ids(config: Cfg) -> MLE<Vec<String>> { 605pub fn lists_get_all_ids(config: &Cfg) -> MLE<Vec<String>> {
579 let data = format!("{}/data.db", config.data); 606 let data = format!("{}/data.db", config.data);
580 let connection = Connection::open(data).unwrap(); 607 let connection = Connection::open(data).unwrap();
581 608
@@ -594,7 +621,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE<Vec<String>> {
594} 621}
595 622
596//config 623//config
597pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { 624pub fn config_change_current_list(config: &Cfg, id: &str) -> MLE<()> {
598 let data = format!("{}/data.db", config.data); 625 let data = format!("{}/data.db", config.data);
599 let connection = Connection::open(data)?; 626 let connection = Connection::open(data)?;
600 627
@@ -605,12 +632,13 @@ pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> {
605 Ok(()) 632 Ok(())
606} 633}
607 634
608pub fn config_get_current_list(config: Cfg) -> MLE<String> { 635pub fn config_get_current_list(config: &Cfg) -> MLE<String> {
609 let data = format!("{}/data.db", config.data); 636 let data = format!("{}/data.db", config.data);
610 let connection = Connection::open(data).unwrap(); 637 let connection = Connection::open(data).unwrap();
611 638
612 let mut list_id = String::new(); 639 let mut list_id = String::new();
613 let mut stmt = connection.prepare("SELECT value FROM user_config WHERE id = 'current_list'")?; 640 let mut stmt = connection
641 .prepare("SELECT value FROM user_config WHERE id = 'current_list'")?;
614 let list_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; 642 let list_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?;
615 643
616 for list in list_iter { 644 for list in list_iter {
@@ -626,7 +654,7 @@ pub fn config_get_current_list(config: Cfg) -> MLE<String> {
626 654
627//SETUP(UPDATES) 655//SETUP(UPDATES)
628pub fn s_userlist_update_download( 656pub fn s_userlist_update_download(
629 config: Cfg, 657 config: &Cfg,
630 list_id: String, 658 list_id: String,
631 mod_id: String, 659 mod_id: String,
632 link: String, 660 link: String,
@@ -645,7 +673,9 @@ pub fn s_userlist_update_download(
645 Ok(()) 673 Ok(())
646} 674}
647 675
648pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 676pub fn s_config_create_version(
677 config: &Cfg,
678) -> Result<(), Box<dyn std::error::Error>> {
649 let data = format!("{}/data.db", config.data); 679 let data = format!("{}/data.db", config.data);
650 let connection = Connection::open(data)?; 680 let connection = Connection::open(data)?;
651 681
@@ -656,7 +686,10 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Er
656 Ok(()) 686 Ok(())
657} 687}
658 688
659pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { 689pub fn s_config_update_version(
690 config: &Cfg,
691 ver: String,
692) -> Result<(), Box<dyn std::error::Error>> {
660 let data = format!("{}/data.db", config.data); 693 let data = format!("{}/data.db", config.data);
661 let connection = Connection::open(data)?; 694 let connection = Connection::open(data)?;
662 695
@@ -667,12 +700,15 @@ pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn s
667 Ok(()) 700 Ok(())
668} 701}
669 702
670pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { 703pub fn s_config_get_version(
704 config: &Cfg,
705) -> Result<String, Box<dyn std::error::Error>> {
671 let data = format!("{}/data.db", config.data); 706 let data = format!("{}/data.db", config.data);
672 let connection = Connection::open(data)?; 707 let connection = Connection::open(data)?;
673 708
674 let mut version: String = String::new(); 709 let mut version: String = String::new();
675 let mut stmt = connection.prepare("SELECT value FROM user_config WHERE id = 'db_version'")?; 710 let mut stmt = connection
711 .prepare("SELECT value FROM user_config WHERE id = 'db_version'")?;
676 let ver_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; 712 let ver_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?;
677 713
678 for ver in ver_iter { 714 for ver in ver_iter {
@@ -689,7 +725,7 @@ pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::E
689} 725}
690 726
691pub fn s_insert_column( 727pub fn s_insert_column(
692 config: Cfg, 728 config: &Cfg,
693 table: String, 729 table: String,
694 column: String, 730 column: String,
695 c_type: String, 731 c_type: String,