diff --git a/src/rust/core/file.rs b/src/rust/core/file.rs new file mode 100644 index 0000000..9192ff3 --- /dev/null +++ b/src/rust/core/file.rs @@ -0,0 +1,39 @@ +use color_eyre::eyre::{eyre, Result}; +use sqlx::{query, sqlite::SqliteRow, Error, FromRow}; +use tracing::error; + +use crate::{kinds::ServiceItemKind, model::get_db, service_items::ServiceItem, slides::TextAlignment, songs::Song}; + + +pub fn save(list: Vec) -> Result<()> { + let mut db = get_db(); + let rt = tokio::runtime::Runtime::new().unwrap(); + for item in list { + match item.kind { + ServiceItemKind::Song => { + rt.block_on(async { + let result = query(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 = $1"#).bind(item.database_id).fetch_one(&mut db).await; + process_song(result); + }); + }, + ServiceItemKind::Image => { + todo!() + }, + ServiceItemKind::Video => { + todo!() + }, + ServiceItemKind::Presentation(_) => { + todo!() + }, + ServiceItemKind::Content => { + todo!() + }, + } + } + Ok(()) +} + +fn process_song(song_result: Result) -> Result<()> { + let song = Song::from_row(&song_result?)?; + Ok(()) +}