summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-03 11:56:17 +0200
committerfxqnlr <[email protected]>2023-05-03 11:56:17 +0200
commit5a1196c3c98a48028bf70576b5f946f7a0475e07 (patch)
tree27a31ebd8fe82638f96e733bcb36e94d990da1da
parent87947ce38476e7a5fb8d4db1bc9e0b584aa965ca (diff)
downloadmodlist-5a1196c3c98a48028bf70576b5f946f7a0475e07.tar
modlist-5a1196c3c98a48028bf70576b5f946f7a0475e07.tar.gz
modlist-5a1196c3c98a48028bf70576b5f946f7a0475e07.zip
added id to db lookup
-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 = ?")?;