summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2020-05-18 11:25:02 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2020-05-18 11:25:02 -0400
commit57f2f9f21a82a8b13c544d62d353894eb3e0a4c7 (patch)
tree7e39ca248d55ca3b8fdf9a06c5cfef68a6ef9b32 /src
parent5102eb8d425da6d925c745856b914961076de7aa (diff)
Implement `add_tag`.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs13
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() {