diff --git a/src/tags.rs b/src/tags.rs index a55fbe5..a481b8f 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -185,7 +185,7 @@ pub struct SqliteTagDao { } impl SqliteTagDao { - fn new(connection: SqliteConnection) -> Self { + pub(crate) fn new(connection: SqliteConnection) -> Self { SqliteTagDao { connection } } } @@ -235,8 +235,7 @@ impl TagDao for SqliteTagDao { .and_then(|id| { debug!("Got id: {:?} for inserted tag: {:?}", id, name); tags::table - .left_join(tagged_photo::table) - .filter(tagged_photo::id.eq(id)) + .filter(tags::id.eq(id)) .select((tags::id, tags::name, tags::created_time)) .get_result::(self.connection.borrow_mut()) .with_context(|| "Unable to get tagged photo from Sqlite") @@ -274,13 +273,29 @@ impl TagDao for SqliteTagDao { created_time: Utc::now().timestamp(), }) .execute(self.connection.borrow_mut()) - .with_context(|| "Unable to tag file in sqlite") + .with_context(|| format!("Unable to tag file {:?} in sqlite", path)) + .and_then(|_| { + debug!("Inserted tagged photo: {:#} -> {:?}", tag_id, path); + no_arg_sql_function!( + last_insert_rowid, + diesel::sql_types::Integer, + "Represents the SQL last_insert_row() function" + ); + diesel::select(last_insert_rowid) + .get_result::(&mut self.connection) + .with_context(|| "Unable to get last inserted tag from Sqlite") + }) .and_then(|tagged_id| { debug!("Inserted tagged photo: {:?}", tagged_id); tagged_photo::table .find(tagged_id as i32) .first(self.connection.borrow_mut()) - .with_context(|| "Error getting inserted tagged photo") + .with_context(|| { + format!( + "Error getting inserted tagged photo with id: {:?}", + tagged_id + ) + }) }) } }