diff --git a/src/main.rs b/src/main.rs index 8741360..e71d03a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,8 +41,8 @@ fn init_db() -> anyhow::Result<()> { conn.execute( r#"CREATE TABLE file_tag( - file_id INT REFERENCES file(id), - tag_id INT REFERENCES tag(id), + file_id INTEGER REFERENCES file(id) ON DELETE CASCADE, + tag_id INTEGER REFERENCES tag(id) ON DELETE CASCADE, PRIMARY KEY (file_id, tag_id) );"#, (), diff --git a/src/tags.rs b/src/tags.rs index 5743b81..ffb6b7e 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -6,7 +6,7 @@ use std::{ use anyhow::{Result, anyhow}; -use rusqlite::{Connection, params, params_from_iter}; +use rusqlite::{Connection, params, params_from_iter, types::Value}; use crate::{ cli::{self, FilesArgs, TagArgs, TagsArgs, UntagArgs}, @@ -255,19 +255,20 @@ fn untag_file(conn: &mut Connection, file: PathBuf, tags: Option>) - INNER JOIN tag ON file_tag.tag_id = tag.id"# .to_string(); - match tags { + let params = match tags { Some(tags) => { let tags = tags.join(","); sql.push_str(" WHERE file.path = ?1 AND tag.name IN (?2))"); - let mut stmt = tx.prepare(&sql)?; - stmt.execute(params![file, tags])?; + vec![Value::Text(file), Value::Text(tags)] } None => { sql.push_str(" WHERE file.path = ?1)"); - let mut stmt = tx.prepare(&sql)?; - stmt.execute(params![file])?; + vec![Value::Text(file)] } }; + + let mut stmt = tx.prepare(&sql)?; + stmt.execute(params_from_iter(params))?; } tx.commit()?;