From d831a9340652f8a259c0764788b8914b6204beac Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Mon, 18 May 2020 11:59:54 -0400 Subject: Implement `tag_image`. --- src/main.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.rs b/src/main.rs index e7febe4..3e821c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,6 +88,19 @@ 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 + .conn + .prepare("SELECT * FROM tags WHERE name = ?")? + .query_row(params![tag], |row| Ok(row.get(0)))??; + self.conn.execute( + "INSERT INTO mapping (image, tag) VALUES(?, ?)", + params![image_id, tag_id], + )?; + Ok(()) + } } fn main() { -- cgit v1.3