summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2020-05-19 21:37:02 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2020-05-21 17:04:51 -0400
commit8de57fec67898ceeebd7620b1b5ba6bd423fb2fd (patch)
treee427f9376e421e4dc69e65afb2b9e5371f9d5836
parent4fb0bc7537485de5931452c8d4baf15bec742712 (diff)
Factor out `tag_id`.
-rw-r--r--src/main.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 91458e0..0809159 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -124,19 +124,25 @@ impl TagBase {
Ok(())
}
- /// Associate `tag` with the image specified by `image_id`.
- fn tag_image(&self, image_id: i64, tag: &str) -> Result<()> {
- let tag_id: i64 = self
+ /// Return the internal id for `tag`.
+ fn tag_id(&self, tag: &str) -> Result<i64> {
+ Ok(self
.conn
.prepare("SELECT * FROM tags WHERE name = ?")?
- .query_row(params![tag], |row| Ok(row.get(0)))??;
+ .query_row(params![tag], |row| Ok(row.get::<_, String>(0)))??
+ .parse::<i64>()?)
+ }
+
+ /// Associate `tag` with the image specified by `image_id`.
+ fn tag_image(&self, image_id: i64, tag: &str) -> Result<()> {
self.conn.execute(
"INSERT INTO mapping (image, tag) VALUES(?, ?)",
- params![image_id, tag_id],
+ params![image_id, self.tag_id(tag)?],
)?;
Ok(())
}
+ /// Return the tags for the image specified by `image_id`.
fn tags_for_image(&self, image_id: i64) -> Result<Vec<String>> {
Ok(self
.conn