summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2022-12-07 17:45:16 +0100
committerFxQnLr <[email protected]>2022-12-07 17:45:16 +0100
commit758e608e6c331df2a5900de7f932f9b498573ed1 (patch)
tree4ec306b7b69613286f1d070a52c7b26d6280b111 /src/db.rs
parent2ec20c50e7c02d82b248835988df040bd266b659 (diff)
downloadmodlist-758e608e6c331df2a5900de7f932f9b498573ed1.tar
modlist-758e608e6c331df2a5900de7f932f9b498573ed1.tar.gz
modlist-758e608e6c331df2a5900de7f932f9b498573ed1.zip
groundwork for downloads; cleanup
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/db.rs b/src/db.rs
index 9d862d6..cd32d1f 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -122,7 +122,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> Result<Vec<DBModlist
122 let mut wherestr = String::from("WHERE"); 122 let mut wherestr = String::from("WHERE");
123 for (i, id) in mods.iter().enumerate() { 123 for (i, id) in mods.iter().enumerate() {
124 let mut or = " OR"; 124 let mut or = " OR";
125 if i == mods.len() - 1 { or = "" }; 125 if i == mods.len() - 1 { or = "" };
126 wherestr = format!("{} id = '{}'{}", wherestr, id, or); 126 wherestr = format!("{} id = '{}'{}", wherestr, id, or);
127 } 127 }
128 128
@@ -209,6 +209,26 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St
209 } 209 }
210} 210}
211 211
212pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> {
213 let data = format!("{}/data.db", config.data);
214 let connection = Connection::open(data)?;
215
216 let mut versions: Vec<(String, String)> = Vec::new();
217 let mut stmt = connection.prepare(format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str())?;
218 let id_iter = stmt.query_map([], |row| {
219 Ok(vec![row.get::<usize, String>(0)?, row.get::<usize, String>(1)?])
220 })?;
221
222 for ver in id_iter {
223 let out = ver?;
224 versions.push((out[0].to_owned(), out[1].to_owned()));
225 };
226
227 if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); };
228
229 Ok(versions)
230}
231
212pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { 232pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> {
213 let data = format!("{}/data.db", config.data); 233 let data = format!("{}/data.db", config.data);
214 let connection = Connection::open(data).unwrap(); 234 let connection = Connection::open(data).unwrap();
@@ -248,6 +268,26 @@ pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Res
248 Ok(versions) 268 Ok(versions)
249} 269}
250 270
271pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> {
272 let data = format!("{}/data.db", config.data);
273 let connection = Connection::open(data)?;
274
275 let mut versions: Vec<(String, String)> = Vec::new();
276 let mut stmt = connection.prepare(format!("SELECT mod_id, current_version FROM {}", list_id).as_str())?;
277 let id_iter = stmt.query_map([], |row| {
278 Ok(vec![row.get::<usize, String>(0)?, row.get::<usize, String>(1)?])
279 })?;
280
281 for ver in id_iter {
282 let out = ver?;
283 versions.push((out[0].to_owned(), out[1].to_owned()));
284 };
285
286 if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); };
287
288 Ok(versions)
289}
290
251pub 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>> { 291pub 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>> {
252 let data = format!("{}/data.db", config.data); 292 let data = format!("{}/data.db", config.data);
253 let connection = Connection::open(data)?; 293 let connection = Connection::open(data)?;