adding file.rs
This commit is contained in:
parent
3c87385895
commit
f3c3e98e16
1 changed files with 39 additions and 0 deletions
39
src/rust/core/file.rs
Normal file
39
src/rust/core/file.rs
Normal file
|
@ -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<ServiceItem>) -> 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<SqliteRow, Error>) -> Result<()> {
|
||||
let song = Song::from_row(&song_result?)?;
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue