diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -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 | ||
212 | pub 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 | |||
212 | pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { | 232 | pub 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 | ||
271 | pub 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 | |||
251 | pub 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>> { | 291 | pub 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)?; |