From be30ec660fe5915b9635edd1e1cae3d69c9f5804 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 14 Nov 2024 13:32:53 +0200 Subject: [PATCH] use shared pointer for profile_id value --- src/profile.rs | 4 ++-- src/profile/bookmark.rs | 2 +- src/profile/bookmark/database.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/profile.rs b/src/profile.rs index 75445af7..038b87e6 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -83,13 +83,13 @@ impl Profile { let database = Rc::new(Database::new(connection.clone())); // Get active profile or create new one - let profile_id = match database.active() { + let profile_id = Rc::new(match database.active() { Some(profile) => profile.id, None => match database.add(true, DateTime::now_local().unwrap(), None) { Ok(id) => id, Err(_) => todo!(), }, - }; + }); // Result Self { diff --git a/src/profile/bookmark.rs b/src/profile/bookmark.rs index 7fc54735..222ccd75 100644 --- a/src/profile/bookmark.rs +++ b/src/profile/bookmark.rs @@ -19,7 +19,7 @@ impl Bookmark { // Constructors /// Create new `Self` - pub fn new(connection: Rc>, profile_id: i64) -> Self { + pub fn new(connection: Rc>, profile_id: Rc) -> Self { // Init children components let database = Rc::new(Database::new(connection, profile_id)); let memory = Rc::new(Memory::new()); diff --git a/src/profile/bookmark/database.rs b/src/profile/bookmark/database.rs index 4a31fcd3..0a4866c4 100644 --- a/src/profile/bookmark/database.rs +++ b/src/profile/bookmark/database.rs @@ -11,14 +11,14 @@ pub struct Table { pub struct Database { connection: Rc>, - profile_id: i64, // multi-profile relationship @TODO shared reference? + profile_id: Rc, // multi-profile relationship } impl Database { // Constructors /// Create new `Self` - pub fn new(connection: Rc>, profile_id: i64) -> Self { + pub fn new(connection: Rc>, profile_id: Rc) -> Self { Self { connection, profile_id, @@ -31,7 +31,7 @@ impl Database { pub fn records(&self, request: Option<&str>) -> Vec { let readable = self.connection.read().unwrap(); let tx = readable.unchecked_transaction().unwrap(); - select(&tx, self.profile_id, request).unwrap() + select(&tx, *self.profile_id, request).unwrap() } // Setters @@ -44,7 +44,7 @@ impl Database { let tx = writable.transaction().unwrap(); // Create new record - insert(&tx, self.profile_id, time, request).unwrap(); + insert(&tx, *self.profile_id, time, request).unwrap(); // Hold insert ID for result let id = last_insert_id(&tx);