diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-19 20:30:02 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-20 19:37:26 -0400 |
| commit | 35bb67227b8fee2b798465b1a5607455f60e9f7f (patch) | |
| tree | 1e5a539471ee9a75439b7087eeee47d4c4b758aa | |
| parent | ece1c6fcf4fe51ce6e57f3c261a042ff9e84faf1 (diff) | |
[database] return untagged images in an empty query.
| -rw-r--r-- | src/database.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/database.rs b/src/database.rs index 4e33fa7..e5ea02f 100644 --- a/src/database.rs +++ b/src/database.rs @@ -320,20 +320,27 @@ impl TagDatabase { let query = format!( "SELECT files.id FROM files - JOIN mapping - ON files.id = mapping.file - WHERE {predicate} + {predicate} {since} GROUP BY files.id ORDER BY files.id DESC {limit}", - predicate = if predicates.is_empty() { - "1 == 1".into() + predicate = if q.is_empty() { + "".into() } else { - predicates.join(" AND ") + format!( + "JOIN mapping + ON files.id = mapping.file + WHERE {predicate}", + predicate = predicates.join(" AND ") + ) }, since = if let Some(ref keyset) = k { - format!("AND files.id < {}", keyset.last_id) + if q.is_empty() { + format!("WHERE files.id < {}", keyset.last_id) + } else { + format!("AND files.id < {}", keyset.last_id) + } } else { "".into() }, @@ -536,7 +543,7 @@ mod tests { #[test] fn test_empty_query() { let tb = TagDatabase::new_mem().unwrap(); - tb.add_file("test1", &vec!["tag1"]).unwrap(); + tb.add_file("test1", &Vec::<String>::new()).unwrap(); tb.add_file("test2", &vec!["tag1"]).unwrap(); let query = parse_query("").unwrap(); |