diff options
author | fx <[email protected]> | 2023-05-04 14:33:23 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-05-04 14:33:23 +0200 |
commit | 0c7ba29d3e17c47e5fc9cffe78c28a0019d453b7 (patch) | |
tree | 1815f82eaa9e84f8f73683a84ed99063e4e0d904 /src/db.rs | |
parent | 2b180daf1e2687436046b853c59e0abe12c50f57 (diff) | |
parent | 59d539f756375719f7ff71822c72afa00c3bd3c4 (diff) | |
download | modlist-0c7ba29d3e17c47e5fc9cffe78c28a0019d453b7.tar modlist-0c7ba29d3e17c47e5fc9cffe78c28a0019d453b7.tar.gz modlist-0c7ba29d3e17c47e5fc9cffe78c28a0019d453b7.zip |
Merge pull request 'config' (#4) from config into master
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/4
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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 |
52 | pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> { | 52 | pub 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 = ?")?; |