trying to move slide building to more backend focused

This commit is contained in:
Chris Cochrun 2024-10-02 10:38:40 -05:00
parent 836c997e97
commit 6052cd01ac
6 changed files with 113 additions and 20 deletions

View file

@ -249,6 +249,7 @@ use sqlx::{query, query_as, Connection, SqliteConnection};
use std::collections::HashMap;
use std::pin::Pin;
use tracing::{debug, error};
use color_eyre::Result;
use self::song_model::{
QHash_i32_QByteArray, QMap_QString_QVariant, QVector_i32,
@ -315,6 +316,29 @@ impl Default for SongModelRust {
}
}
const SELECT_SINGLE_SONG_STATEMENT: &'static str = r#"SELECT vorder as "verse_order!", fontSize as "font_size!: i32", backgroundType as "background_type!", horizontalTextAlignment as "horizontal_text_alignment!", verticalTextAlignment as "vertical_text_alignment!", title as "title!", font as "font!", background as "background!", lyrics as "lyrics!", ccli as "ccli!", author as "author!", audio as "audio!", id as "id: i32" from songs where id = ?"#;
impl SongModelRust {
pub fn get_song(id: i32) -> Result<Song> {
let rt = tokio::runtime::Runtime::new().unwrap();
let mut db = {
let mut data = dirs::data_local_dir().unwrap();
data.push("lumina");
data.push("library-db.sqlite3");
let mut db_url = String::from("sqlite://");
db_url.push_str(data.to_str().unwrap());
rt.block_on(async {
SqliteConnection::connect(&db_url).await.expect("problems")
})
};
rt.block_on(async {
let statement = format!("{} where id = ?", SELECT_SONG_STATEMENT).as_str();
let result = query_as!(Song, SELECT_SINGLE_SONG_STATEMENT, id).fetch_one(&mut db).await?;
Ok(result)
})
}
}
impl song_model::SongModel {
pub fn clear(mut self: Pin<&mut Self>) {
unsafe {