summaryrefslogtreecommitdiff
path: root/src/database.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.rs')
-rw-r--r--src/database.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/database.rs b/src/database.rs
index d27646b..7b69a21 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -26,9 +26,9 @@ pub struct TagDatabase(Connection);
/// Tag query with a sense of "state" for pagination.
#[derive(Debug)]
pub struct Query<'a> {
- tags: &'a [&'a str],
- last_id: Option<i64>,
- limit: Option<i64>,
+ pub tags: &'a [&'a str],
+ pub last_id: Option<i64>,
+ pub limit: Option<i64>,
}
impl TagDatabase {
@@ -144,6 +144,22 @@ impl TagDatabase {
Ok(())
}
+ /// Return the tags for the image specified by `image_id`.
+ pub fn tags_for_image(&self, image_id: i64) -> Result<Vec<String>> {
+ Ok(self
+ .0
+ .prepare(
+ "SELECT tags.name, COUNT(mapping.tag) as tag_count
+ FROM mapping
+ INNER JOIN images ON images.id = ?
+ INNER JOIN tags
+ GROUP BY tags.name;",
+ )?
+ .query_map(params![image_id], |row| row.get(0))?
+ .filter_map(|tag| tag.ok())
+ .collect())
+ }
+
/// Return the intersection of the sets of images matching each of `tags`.
pub fn query(&self, q: Query) -> Result<Vec<Image>> {
let ids: Vec<i64> = q
@@ -257,22 +273,6 @@ mod tests {
tb.initialize_tables()?;
Ok(tb)
}
-
- /// Return the tags for the image specified by `image_id`.
- pub fn tags_for_image(&self, image_id: i64) -> Result<Vec<String>> {
- Ok(self
- .0
- .prepare(
- "SELECT tags.name, COUNT(mapping.tag) as tag_count
- FROM mapping
- INNER JOIN images ON images.id = ?
- INNER JOIN tags
- GROUP BY tags.name;",
- )?
- .query_map(params![image_id], |row| row.get(0))?
- .filter_map(|tag| tag.ok())
- .collect())
- }
}
#[test]