From ba51c5616966dc1e75898bb37db71247fde5d4bd Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 9 Oct 2024 13:39:40 -0500 Subject: [PATCH] update todo --- TODO.org | 3 +++ src/rust/core/images.rs | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/TODO.org b/TODO.org index 8e6ad48..183bc66 100644 --- a/TODO.org +++ b/TODO.org @@ -44,6 +44,9 @@ I've got SlideType enums working *** Move logic of changing slides to slide_model Since the slide_object is merely supposed to be the view of the current slide, deciding which slide to switch to should be entirely on the slide_model, not the slide_object. This way slide_object doesn't need to know anything about the which slide is next and instead have a function to update everything to the slide returned from slide_model's new slide. +*** Move all big logic to library crate for using rust data types better +I've started to move all the real logic to a pure rust library that can be consumed and used by the cxx-qt rust parts in QML. This could also pave the way to using any other rust gui instead of QML in the future. + ** TODO [#A] Consider converting diesel to raw sqlx instead From what I can gather, sometimes an orm is just too hard to work around rather than doing raw sql queries. The only issue is that my queries have been rather small. I only really need to select everything into the app and then run it from there. However, it could still be a consideration as things age. Perhaps when there are hundreds or even thousands of items in the database, it'll be more effective to use something like SQLx. diff --git a/src/rust/core/images.rs b/src/rust/core/images.rs index 9672649..bfe6d2d 100644 --- a/src/rust/core/images.rs +++ b/src/rust/core/images.rs @@ -1,10 +1,12 @@ -use std::path::PathBuf; -use sqlx::query_as; -use tracing::error; use crate::model::Model; +use serde::{Deserialize, Serialize}; +use sqlx::query_as; +use std::path::PathBuf; +use tracing::error; -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct Image { + pub id: i32, pub title: String, pub path: PathBuf, } @@ -13,14 +15,14 @@ impl Model { pub fn load_from_db(&mut self) { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { - let result = query_as!(Image, r#"SELECT title as "title!", filePath as "path!" from images"#).fetch_all(&mut self.db).await; + let result = query_as!(Image, r#"SELECT title as "title!", filePath as "path!", id as "id: i32" from images"#).fetch_all(&mut self.db).await; match result { Ok(v) => { for image in v.into_iter() { let _ = self.add_item(image); } } - Err(e) => error!("There was an error in converting songs: {e}"), + Err(e) => error!("There was an error in converting images: {e}"), } }); } @@ -60,9 +62,16 @@ mod test { match result { Ok(_) => { assert_eq!(&image, image_model.get_item(0).unwrap()); - assert_ne!(&new_image, image_model.get_item(0).unwrap()); + assert_ne!( + &new_image, + image_model.get_item(0).unwrap() + ); } - Err(e) => assert!(false, "There was an error adding the image: {:?}", e), + Err(e) => assert!( + false, + "There was an error adding the image: {:?}", + e + ), } } }