diff options
| -rw-r--r-- | src/main.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index 2739f42..e7febe4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,9 +51,9 @@ impl TagBase { } /// Insert the image at `path` into the data. - fn import_image(&self, path: &Path) -> Result<i32> { + fn import_image(&self, path: &Path) -> Result<i64> { if path.is_dir() { - return Err(anyhow!("`path` does not name a file.")); + bail!("`path` does not name a file."); } let mut file = std::fs::File::open(path)?; @@ -69,17 +69,11 @@ impl TagBase { let split_index = path.len() - file_name.len(); let parent_directory = &path[0..split_index]; - self.conn.execute( - "INSERT INTO images (blake2, filename, orig_dir) VALUES(?,?,?)", - params![hash, file_name, parent_directory], - )?; - - let id: Vec<std::result::Result<i32, rusqlite::Error>> = self + let id = self .conn - .prepare("SELECT id FROM images WHERE blake2 = ?;")? - .query_and_then(params![hash], |row| row.get(0))? - .collect(); - Ok(*id[0].as_ref().unwrap()) + .prepare("INSERT INTO images (blake2, filename, orig_dir) VALUES(?,?,?)")? + .insert(params![hash, file_name, parent_directory])?; + Ok(id) } /// Insert `tag` into the database, if it does not already exist. |