summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/db.rs b/src/db.rs
index abfe1dd..6c7e4f8 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -50,8 +50,6 @@ pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::
50/// 50///
51///Will return `MLError` when no mod id is found 51///Will return `MLError` when no mod id is found
52pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> { 52pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> {
53 //TODO check if "slug" is id
54
55 let data = format!("{}/data.db", data); 53 let data = format!("{}/data.db", data);
56 let connection = Connection::open(data)?; 54 let connection = Connection::open(data)?;
57 55
@@ -64,6 +62,15 @@ pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> {
64 for id in id_iter { 62 for id in id_iter {
65 mod_id = id?; 63 mod_id = id?;
66 } 64 }
65 //get from id if no slug found
66 if mod_id.is_empty() {
67 let mut stmt = connection.prepare("SELECT id FROM mods WHERE id = ?")?;
68 let id_iter = stmt.query_map([slug], |row| row.get::<usize, String>(0))?;
69
70 for id in id_iter {
71 mod_id = id?;
72 }
73 }
67 //get from title if no id found from slug 74 //get from title if no id found from slug
68 if mod_id.is_empty() { 75 if mod_id.is_empty() {
69 let mut stmt = connection.prepare("SELECT id FROM mods WHERE title = ?")?; 76 let mut stmt = connection.prepare("SELECT id FROM mods WHERE title = ?")?;