diff options
| -rw-r--r-- | src/main.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index ed0965c..2739f42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,19 @@ impl TagBase { .collect(); Ok(*id[0].as_ref().unwrap()) } + + /// Insert `tag` into the database, if it does not already exist. + fn add_tag(&self, tag: &str) -> Result<()> { + let exists = self + .conn + .prepare("SELECT * FROM tags WHERE name = ?")? + .exists(params![tag]); + if let Err(_) = exists { + self.conn + .execute("INSERT INTO tags (name) VALUES(?)", params![tag])?; + } + Ok(()) + } } fn main() { |