Saving functionality is looking better
This commit is contained in:
parent
3e1e46ce2b
commit
a99e4fb3cf
15 changed files with 421 additions and 54 deletions
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf};
|
|||
|
||||
use color_eyre::eyre::{eyre, Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{query, query_as, sqlite::SqliteRow, FromRow, Row};
|
||||
use sqlx::{query, query_as, sqlite::SqliteRow, FromRow, Row, SqliteConnection};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::{
|
||||
|
@ -76,16 +76,9 @@ impl FromRow<'_, SqliteRow> for Song {
|
|||
}
|
||||
|
||||
|
||||
pub fn get_song_from_db(index: i32) -> Result<Song> {
|
||||
let mut db = get_db();
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
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(index).fetch_one(&mut db).await;
|
||||
match result {
|
||||
Ok(record) => Ok(Song::from_row(&record)?),
|
||||
Err(e) => Err(eyre!("There was an error getting the song from the db: {e}")),
|
||||
}
|
||||
})
|
||||
pub async fn get_song_from_db(index: i32, db: &mut SqliteConnection) -> Result<Song> {
|
||||
let row = 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(index).fetch_one(db).await?;
|
||||
Ok(Song::from_row(&row)?)
|
||||
}
|
||||
|
||||
|
||||
|
@ -290,10 +283,10 @@ You saved my soul"
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_song_from_db() {
|
||||
#[tokio::test]
|
||||
pub async fn test_song_from_db() {
|
||||
let song = test_song();
|
||||
let result = get_song_from_db(7);
|
||||
let result = get_song_from_db(7, &mut get_db().await).await;
|
||||
match result {
|
||||
Ok(db_song) => assert_eq!(song, db_song),
|
||||
Err(e) => assert!(false, "{e}"),
|
||||
|
@ -340,7 +333,7 @@ You saved my soul"
|
|||
"E1".to_string(),
|
||||
"E2".to_string(),
|
||||
]),
|
||||
background: Some(Background::try_from("file:///home/chris/nc/tfc/openlp/CMG - Bright Mountains 01.jpg".to_string()).unwrap()),
|
||||
background: Some(Background::try_from("file:///home/chris/nc/tfc/openlp/CMG - Bright Mountains 01.jpg").unwrap()),
|
||||
text_alignment: Some(TextAlignment::MiddleCenter),
|
||||
font: Some("Quicksand Bold".to_string()),
|
||||
font_size: Some(60)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue