trying to tweak sqlx

This commit is contained in:
Chris Cochrun 2025-02-27 15:30:08 -06:00
parent 4fe68236ea
commit 804850505e
11 changed files with 129 additions and 219 deletions

View file

@ -374,6 +374,24 @@ pub async fn get_song_from_db(
}
impl Model<Song> {
pub async fn update_song(
&mut self,
item: Song,
index: i32,
db: &mut SqliteConnection,
) -> Result<()> {
self.update_item(item, index)?;
query!(
r#"UPDATE songs SET title = {} WHERE id = {}"#,
item.title,
item.id
)
.fetch_one(db)
.await?;
Ok(())
}
pub async fn new_song_model(db: &mut SqliteConnection) -> Self {
let mut model = Self {
items: vec![],

View file

@ -418,17 +418,114 @@ impl cosmic::Application for App {
Message::SongEditor(message) => {
debug!(?message);
match message {
song_editor::Message::UpdateSong(ref song) => {
debug!(?song);
if let Some(library) = self.library.as_mut() {
match library.update_song(song.clone()) {
Ok(_) => {
debug!("upated song")
song_editor::Message::ChangeFont(ref font) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.font = Some(font.to_string());
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeFontSize(
font_size,
) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.font_size = Some(font_size as i32);
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeTitle(ref title) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.title = title.to_string();
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeVerseOrder(
ref vo,
) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
let verse_order = vo
.split(" ")
.into_iter()
.map(|s| s.to_owned())
.collect();
song.verse_order = Some(verse_order);
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeLyrics(
ref action,
) => {
self.song_editor
.lyrics
.perform(action.clone());
let lyrics = self.song_editor.lyrics.text();
if let Some(mut song) =
self.song_editor.song.clone()
{
song.lyrics = Some(lyrics.to_string());
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::ChangeAuthor(
ref author,
) => {
if let Some(mut song) =
self.song_editor.song.clone()
{
song.author = Some(author.to_string());
self.song_editor.song =
Some(song.clone());
if let Some(library) = &mut self.library {
match library.update_song(song) {
Ok(_) => (),
Err(e) => error!(?e),
}
};
};
}
song_editor::Message::Edit(_) => todo!(),
_ => (),
};
self.song_editor.update(message).map(|m| {

View file

@ -79,6 +79,7 @@ impl Library {
Message::RemoveItem => Task::none(),
Message::OpenItem(item) => {
debug!(?item);
self.editing_item = item;
Task::none()
}
Message::HoverLibrary(library_kind) => {

View file

@ -26,7 +26,7 @@ use super::presenter::slide_view;
#[derive(Debug)]
pub struct SongEditor {
song: Option<Song>,
pub song: Option<Song>,
title: String,
fonts: combo_box::State<String>,
font_sizes: Vec<String>,
@ -35,7 +35,7 @@ pub struct SongEditor {
audio: PathBuf,
font_size: usize,
verse_order: String,
lyrics: text_editor::Content,
pub lyrics: text_editor::Content,
editing: bool,
background: Option<Background>,
video: Option<Video>,
@ -157,13 +157,7 @@ impl SongEditor {
}
Message::ChangeTitle(title) => {
self.title = title.clone();
if let Some(mut song) = self.song.clone() {
debug!(title);
song.title = title;
self.update(Message::UpdateSong(song))
} else {
Task::none()
}
Task::none()
}
Message::ChangeVerseOrder(verse_order) => {
self.verse_order = verse_order.clone();