diff --git a/src/model/logbook.rs b/src/model/logbook.rs index b856afa..21913c3 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -145,6 +145,20 @@ impl From for LogbookCreateError { } impl Logbook { + pub async fn find_by_id_tx(db: &mut Transaction<'_, Sqlite>, id: i32) -> Option { + sqlx::query_as!( + Self, + " + SELECT id,boat_id,shipmaster,steering_person,shipmaster_only_steering,departure,arrival,destination,distance_in_km,comments,logtype + FROM logbook + WHERE id like ? + ", + id + ) + .fetch_one(db) + .await + .ok() + } pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option { sqlx::query_as!( Self, @@ -273,7 +287,9 @@ ORDER BY departure DESC .fetch_one(&mut tx) .await.unwrap().id; - let logbook = Logbook::find_by_id(db, inserted_row as i32).await.unwrap(); //ok + let logbook = Logbook::find_by_id_tx(&mut tx, inserted_row as i32) + .await + .unwrap(); //ok return match logbook .home_with_transaction(&mut tx, created_by_user, log_to_finalize)