summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-02-19 11:49:23 +0100
committerfxqnlr <[email protected]>2023-02-19 11:49:23 +0100
commit9c984cef9a2d0fb223635617934959480e8ca2df (patch)
tree4e9bcae11b2f028822591ea2948e311dded2de10 /src/db.rs
parentff23a11e632812b685f594324e6004c6da81cd4d (diff)
downloadmodlist-9c984cef9a2d0fb223635617934959480e8ca2df.tar
modlist-9c984cef9a2d0fb223635617934959480e8ca2df.tar.gz
modlist-9c984cef9a2d0fb223635617934959480e8ca2df.zip
Added adding of specific mod-version
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/db.rs b/src/db.rs
index ecc6854..a7c149c 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -82,23 +82,29 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> {
82 Ok(mod_id) 82 Ok(mod_id)
83} 83}
84 84
85pub fn mods_get_title(config: Cfg, id: &str) -> MLE<String> { 85pub struct ModInfo {
86 pub slug: String,
87 pub title: String,
88}
89
90pub fn mods_get_info(config: Cfg, id: &str) -> MLE<ModInfo> {
86 let data = devdir(format!("{}/data.db", config.data).as_str()); 91 let data = devdir(format!("{}/data.db", config.data).as_str());
87 let connection = Connection::open(data)?; 92 let connection = Connection::open(data)?;
88 93
89 let mut mod_name = String::new(); 94 let mut mod_info: Option<ModInfo> = None;
90 let mut stmt = connection.prepare("SELECT title FROM mods WHERE id = ?")?; 95 let mut stmt = connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?;
91 let name_iter = stmt.query_map([id], |row| { 96 let name_iter = stmt.query_map([id], |row| {
92 row.get::<usize, String>(0) 97 Ok(vec![row.get::<usize, String>(0)?, row.get::<usize, String>(1)?])
93 })?; 98 })?;
94 99
95 for name in name_iter { 100 for info in name_iter {
96 mod_name = name?; 101 let i = info?;
102 mod_info = Some(ModInfo { title: String::from(&i[0]), slug: String::from(&i[1]) });
97 }; 103 };
98 104
99 match mod_name.is_empty() { 105 match mod_info.is_none() {
100 true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")), 106 true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")),
101 false => Ok(mod_name), 107 false => Ok(mod_info.unwrap()),
102 } 108 }
103} 109}
104 110