diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 70 |
1 files changed, 35 insertions, 35 deletions
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | //MODS | 11 | //MODS |
12 | pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { | 12 | pub 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,7 @@ pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { | |||
21 | Ok(()) | 21 | Ok(()) |
22 | } | 22 | } |
23 | 23 | ||
24 | pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 24 | pub fn mods_get_all_ids(config: &Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
25 | let data = format!("{}/data.db", config.data); | 25 | let data = format!("{}/data.db", config.data); |
26 | let connection = Connection::open(data).unwrap(); | 26 | let connection = Connection::open(data).unwrap(); |
27 | 27 | ||
@@ -120,7 +120,7 @@ pub fn mods_get_info(config: &Cfg, id: &str) -> MLE<ModInfo> { | |||
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { | 123 | pub fn mods_remove(config: &Cfg, id: String) -> MLE<()> { |
124 | println!("Removing mod {} from database", id); | 124 | println!("Removing mod {} from database", id); |
125 | 125 | ||
126 | let data = format!("{}/data.db", config.data); | 126 | let data = format!("{}/data.db", config.data); |
@@ -137,7 +137,7 @@ pub struct DBModlistVersions { | |||
137 | pub versions: String, | 137 | pub versions: String, |
138 | } | 138 | } |
139 | 139 | ||
140 | pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVersions>> { | 140 | pub fn mods_get_versions(config: &Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVersions>> { |
141 | let data = format!("{}/data.db", config.data); | 141 | let data = format!("{}/data.db", config.data); |
142 | let connection = Connection::open(data)?; | 142 | let connection = Connection::open(data)?; |
143 | 143 | ||
@@ -186,7 +186,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer | |||
186 | 186 | ||
187 | //userlist | 187 | //userlist |
188 | pub fn userlist_insert( | 188 | pub fn userlist_insert( |
189 | config: Cfg, | 189 | config: &Cfg, |
190 | list_id: &str, | 190 | list_id: &str, |
191 | mod_id: &str, | 191 | mod_id: &str, |
192 | current_version: &str, | 192 | current_version: &str, |
@@ -220,7 +220,7 @@ pub fn userlist_insert( | |||
220 | Ok(()) | 220 | Ok(()) |
221 | } | 221 | } |
222 | 222 | ||
223 | pub fn userlist_get_all_ids(config: Cfg, list_id: &str) -> MLE<Vec<String>> { | 223 | pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE<Vec<String>> { |
224 | let data = format!("{}/data.db", config.data); | 224 | let data = format!("{}/data.db", config.data); |
225 | let connection = Connection::open(data).unwrap(); | 225 | let connection = Connection::open(data).unwrap(); |
226 | 226 | ||
@@ -239,7 +239,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: &str) -> MLE<Vec<String>> { | |||
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { | 242 | pub fn userlist_remove(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<()> { |
243 | let data = format!("{}/data.db", config.data); | 243 | let data = format!("{}/data.db", config.data); |
244 | let connection = Connection::open(data)?; | 244 | let connection = Connection::open(data)?; |
245 | 245 | ||
@@ -251,7 +251,7 @@ pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { | |||
251 | } | 251 | } |
252 | 252 | ||
253 | pub fn userlist_get_applicable_versions( | 253 | pub fn userlist_get_applicable_versions( |
254 | config: Cfg, | 254 | config: &Cfg, |
255 | list_id: String, | 255 | list_id: String, |
256 | mod_id: String, | 256 | mod_id: String, |
257 | ) -> MLE<String> { | 257 | ) -> MLE<String> { |
@@ -279,7 +279,7 @@ pub fn userlist_get_applicable_versions( | |||
279 | } | 279 | } |
280 | 280 | ||
281 | pub fn userlist_get_all_applicable_versions_with_mods( | 281 | pub fn userlist_get_all_applicable_versions_with_mods( |
282 | config: Cfg, | 282 | config: &Cfg, |
283 | list_id: String, | 283 | list_id: String, |
284 | ) -> MLE<Vec<(String, String)>> { | 284 | ) -> MLE<Vec<(String, String)>> { |
285 | let data = format!("{}/data.db", config.data); | 285 | let data = format!("{}/data.db", config.data); |
@@ -307,7 +307,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( | |||
307 | Ok(versions) | 307 | Ok(versions) |
308 | } | 308 | } |
309 | 309 | ||
310 | pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE<String> { | 310 | pub fn userlist_get_current_version(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<String> { |
311 | let data = format!("{}/data.db", config.data); | 311 | let data = format!("{}/data.db", config.data); |
312 | let connection = Connection::open(data).unwrap(); | 312 | let connection = Connection::open(data).unwrap(); |
313 | 313 | ||
@@ -327,7 +327,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> | |||
327 | } | 327 | } |
328 | 328 | ||
329 | pub fn userlist_get_all_current_version_ids( | 329 | pub fn userlist_get_all_current_version_ids( |
330 | config: Cfg, | 330 | config: &Cfg, |
331 | list_id: String, | 331 | list_id: String, |
332 | ) -> MLE<Vec<String>> { | 332 | ) -> MLE<Vec<String>> { |
333 | let data = format!("{}/data.db", config.data); | 333 | let data = format!("{}/data.db", config.data); |
@@ -353,7 +353,7 @@ pub fn userlist_get_all_current_version_ids( | |||
353 | } | 353 | } |
354 | 354 | ||
355 | pub fn userlist_get_all_current_versions_with_mods( | 355 | pub fn userlist_get_all_current_versions_with_mods( |
356 | config: Cfg, | 356 | config: &Cfg, |
357 | list_id: String, | 357 | list_id: String, |
358 | ) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { | 358 | ) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { |
359 | let data = format!("{}/data.db", config.data); | 359 | let data = format!("{}/data.db", config.data); |
@@ -384,7 +384,7 @@ pub fn userlist_get_all_current_versions_with_mods( | |||
384 | Ok(versions) | 384 | Ok(versions) |
385 | } | 385 | } |
386 | 386 | ||
387 | pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE<bool> { | 387 | pub fn userlist_get_set_version(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<bool> { |
388 | let data = format!("{}/data.db", config.data); | 388 | let data = format!("{}/data.db", config.data); |
389 | let connection = Connection::open(data).unwrap(); | 389 | let connection = Connection::open(data).unwrap(); |
390 | 390 | ||
@@ -401,7 +401,7 @@ pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE | |||
401 | } | 401 | } |
402 | 402 | ||
403 | pub fn userlist_change_versions( | 403 | pub fn userlist_change_versions( |
404 | config: Cfg, | 404 | config: &Cfg, |
405 | list_id: String, | 405 | list_id: String, |
406 | current_version: String, | 406 | current_version: String, |
407 | versions: String, | 407 | versions: String, |
@@ -416,7 +416,7 @@ pub fn userlist_change_versions( | |||
416 | } | 416 | } |
417 | 417 | ||
418 | pub fn userlist_add_disabled_versions( | 418 | pub fn userlist_add_disabled_versions( |
419 | config: Cfg, | 419 | config: &Cfg, |
420 | list_id: String, | 420 | list_id: String, |
421 | disabled_version: String, | 421 | disabled_version: String, |
422 | mod_id: String, | 422 | mod_id: String, |
@@ -442,7 +442,7 @@ pub fn userlist_add_disabled_versions( | |||
442 | Ok(()) | 442 | Ok(()) |
443 | } | 443 | } |
444 | 444 | ||
445 | pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: String) -> MLE<String> { | 445 | pub fn userlist_get_disabled_versions(config: &Cfg, list_id: String, mod_id: String) -> MLE<String> { |
446 | let data = format!("{}/data.db", config.data); | 446 | let data = format!("{}/data.db", config.data); |
447 | let connection = Connection::open(data).unwrap(); | 447 | let connection = Connection::open(data).unwrap(); |
448 | 448 | ||
@@ -462,7 +462,7 @@ pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: Stri | |||
462 | } | 462 | } |
463 | 463 | ||
464 | pub fn userlist_get_all_downloads( | 464 | pub fn userlist_get_all_downloads( |
465 | config: Cfg, | 465 | config: &Cfg, |
466 | list_id: String, | 466 | list_id: String, |
467 | ) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 467 | ) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
468 | let data = format!("{}/data.db", config.data); | 468 | let data = format!("{}/data.db", config.data); |
@@ -492,11 +492,11 @@ pub fn userlist_get_all_downloads( | |||
492 | //lists | 492 | //lists |
493 | ///Inserts into lists table and creates new table | 493 | ///Inserts into lists table and creates new table |
494 | pub fn lists_insert( | 494 | pub fn lists_insert( |
495 | config: Cfg, | 495 | config: &Cfg, |
496 | id: String, | 496 | id: &str, |
497 | mc_version: String, | 497 | mc_version: &str, |
498 | mod_loader: Modloader, | 498 | mod_loader: &Modloader, |
499 | download_folder: String, | 499 | download_folder: &str, |
500 | ) -> MLE<()> { | 500 | ) -> MLE<()> { |
501 | println!("Creating list {}", id); | 501 | println!("Creating list {}", id); |
502 | 502 | ||
@@ -506,9 +506,9 @@ pub fn lists_insert( | |||
506 | connection.execute( | 506 | connection.execute( |
507 | "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", | 507 | "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", |
508 | [ | 508 | [ |
509 | id.clone(), | 509 | id, |
510 | mc_version, | 510 | mc_version, |
511 | mod_loader.to_string(), | 511 | &mod_loader.to_string(), |
512 | download_folder, | 512 | download_folder, |
513 | ], | 513 | ], |
514 | )?; | 514 | )?; |
@@ -517,7 +517,7 @@ pub fn lists_insert( | |||
517 | Ok(()) | 517 | Ok(()) |
518 | } | 518 | } |
519 | 519 | ||
520 | pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { | 520 | pub fn lists_remove(config: &Cfg, id: String) -> MLE<()> { |
521 | let data = format!("{}/data.db", config.data); | 521 | let data = format!("{}/data.db", config.data); |
522 | let connection = Connection::open(data)?; | 522 | let connection = Connection::open(data)?; |
523 | 523 | ||
@@ -526,7 +526,7 @@ pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { | |||
526 | Ok(()) | 526 | Ok(()) |
527 | } | 527 | } |
528 | 528 | ||
529 | pub fn lists_get(config: Cfg, list_id: String) -> MLE<List> { | 529 | pub fn lists_get(config: &Cfg, list_id: String) -> MLE<List> { |
530 | let data = format!("{}/data.db", config.data); | 530 | let data = format!("{}/data.db", config.data); |
531 | let connection = Connection::open(data).unwrap(); | 531 | let connection = Connection::open(data).unwrap(); |
532 | 532 | ||
@@ -564,7 +564,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE<List> { | |||
564 | Ok(list) | 564 | Ok(list) |
565 | } | 565 | } |
566 | 566 | ||
567 | pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { | 567 | pub fn lists_version(config: &Cfg, list_id: &str, version: &str) -> MLE<()> { |
568 | let data = format!("{}/data.db", config.data); | 568 | let data = format!("{}/data.db", config.data); |
569 | let connection = Connection::open(data).unwrap(); | 569 | let connection = Connection::open(data).unwrap(); |
570 | 570 | ||
@@ -575,7 +575,7 @@ pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { | |||
575 | Ok(()) | 575 | Ok(()) |
576 | } | 576 | } |
577 | 577 | ||
578 | pub fn lists_get_all_ids(config: Cfg) -> MLE<Vec<String>> { | 578 | pub fn lists_get_all_ids(config: &Cfg) -> MLE<Vec<String>> { |
579 | let data = format!("{}/data.db", config.data); | 579 | let data = format!("{}/data.db", config.data); |
580 | let connection = Connection::open(data).unwrap(); | 580 | let connection = Connection::open(data).unwrap(); |
581 | 581 | ||
@@ -594,7 +594,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE<Vec<String>> { | |||
594 | } | 594 | } |
595 | 595 | ||
596 | //config | 596 | //config |
597 | pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { | 597 | pub fn config_change_current_list(config: &Cfg, id: String) -> MLE<()> { |
598 | let data = format!("{}/data.db", config.data); | 598 | let data = format!("{}/data.db", config.data); |
599 | let connection = Connection::open(data)?; | 599 | let connection = Connection::open(data)?; |
600 | 600 | ||
@@ -605,7 +605,7 @@ pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { | |||
605 | Ok(()) | 605 | Ok(()) |
606 | } | 606 | } |
607 | 607 | ||
608 | pub fn config_get_current_list(config: Cfg) -> MLE<String> { | 608 | pub fn config_get_current_list(config: &Cfg) -> MLE<String> { |
609 | let data = format!("{}/data.db", config.data); | 609 | let data = format!("{}/data.db", config.data); |
610 | let connection = Connection::open(data).unwrap(); | 610 | let connection = Connection::open(data).unwrap(); |
611 | 611 | ||
@@ -626,7 +626,7 @@ pub fn config_get_current_list(config: Cfg) -> MLE<String> { | |||
626 | 626 | ||
627 | //SETUP(UPDATES) | 627 | //SETUP(UPDATES) |
628 | pub fn s_userlist_update_download( | 628 | pub fn s_userlist_update_download( |
629 | config: Cfg, | 629 | config: &Cfg, |
630 | list_id: String, | 630 | list_id: String, |
631 | mod_id: String, | 631 | mod_id: String, |
632 | link: String, | 632 | link: String, |
@@ -645,7 +645,7 @@ pub fn s_userlist_update_download( | |||
645 | Ok(()) | 645 | Ok(()) |
646 | } | 646 | } |
647 | 647 | ||
648 | pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 648 | pub fn s_config_create_version(config: &Cfg) -> Result<(), Box<dyn std::error::Error>> { |
649 | let data = format!("{}/data.db", config.data); | 649 | let data = format!("{}/data.db", config.data); |
650 | let connection = Connection::open(data)?; | 650 | let connection = Connection::open(data)?; |
651 | 651 | ||
@@ -656,7 +656,7 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Er | |||
656 | Ok(()) | 656 | Ok(()) |
657 | } | 657 | } |
658 | 658 | ||
659 | pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { | 659 | pub fn s_config_update_version(config: &Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { |
660 | let data = format!("{}/data.db", config.data); | 660 | let data = format!("{}/data.db", config.data); |
661 | let connection = Connection::open(data)?; | 661 | let connection = Connection::open(data)?; |
662 | 662 | ||
@@ -667,7 +667,7 @@ pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn s | |||
667 | Ok(()) | 667 | Ok(()) |
668 | } | 668 | } |
669 | 669 | ||
670 | pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { | 670 | pub fn s_config_get_version(config: &Cfg) -> Result<String, Box<dyn std::error::Error>> { |
671 | let data = format!("{}/data.db", config.data); | 671 | let data = format!("{}/data.db", config.data); |
672 | let connection = Connection::open(data)?; | 672 | let connection = Connection::open(data)?; |
673 | 673 | ||
@@ -689,7 +689,7 @@ pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::E | |||
689 | } | 689 | } |
690 | 690 | ||
691 | pub fn s_insert_column( | 691 | pub fn s_insert_column( |
692 | config: Cfg, | 692 | config: &Cfg, |
693 | table: String, | 693 | table: String, |
694 | column: String, | 694 | column: String, |
695 | c_type: String, | 695 | c_type: String, |