updating songs now works

This commit is contained in:
Chris Cochrun 2025-03-08 22:35:18 -06:00
parent 95fb1d86d8
commit 49e1e767c3
5 changed files with 110 additions and 56 deletions

View file

@ -5,8 +5,8 @@ use crisp::types::{Keyword, Symbol, Value};
use miette::{miette, IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use sqlx::{
query, sqlite::SqliteRow, FromRow, Row, SqliteConnection,
SqlitePool,
pool::PoolConnection, query, sqlite::SqliteRow, FromRow, Row,
Sqlite, SqliteConnection, SqlitePool,
};
use tracing::{debug, error};
@ -375,13 +375,12 @@ pub async fn get_song_from_db(
}
impl Model<Song> {
pub async fn update_song(
pub async fn update_song_in_db(
&mut self,
item: Song,
index: i32,
db: &mut SqliteConnection,
) -> Result<()> {
self.update_item(item.clone(), index)?;
// self.update_item(item.clone(), index)?;
let verse_order = {
if let Some(vo) = item.verse_order {
@ -469,6 +468,65 @@ impl Model<Song> {
}
}
pub async fn update_song_in_db<'a>(
item: Song,
db: PoolConnection<Sqlite>,
) -> Result<()> {
// self.update_item(item.clone(), index)?;
let verse_order = {
if let Some(vo) = item.verse_order {
vo.into_iter()
.map(|mut s| {
s.push_str(" ");
s
})
.collect::<String>()
} else {
String::from("")
}
};
let audio = item
.audio
.map(|a| a.to_str().unwrap_or_default().to_string());
let background = item
.background
.map(|b| b.path.to_str().unwrap_or_default().to_string());
// let text_alignment = item.text_alignment.map(|ta| match ta {
// TextAlignment::TopLeft => todo!(),
// TextAlignment::TopCenter => todo!(),
// TextAlignment::TopRight => todo!(),
// TextAlignment::MiddleLeft => todo!(),
// TextAlignment::MiddleCenter => todo!(),
// TextAlignment::MiddleRight => todo!(),
// TextAlignment::BottomLeft => todo!(),
// TextAlignment::BottomCenter => todo!(),
// TextAlignment::BottomRight => todo!(),
// })
query!(
r#"UPDATE songs SET title = $2, lyrics = $3, author = $4, ccli = $5, verse_order = $6, audio = $7, font = $8, font_size = $9, background = $10 WHERE id = $1"#,
item.id,
item.title,
item.lyrics,
item.author,
item.ccli,
verse_order,
audio,
item.font,
item.font_size,
background
)
.execute(&mut db.detach())
.await
.into_diagnostic()?;
Ok(())
}
impl Song {
pub fn get_lyrics(&self) -> Result<Vec<String>> {
let mut lyric_list = Vec::new();