diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 16 |
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 |