adding a remove_from_db command to model<Song>
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-16 09:35:53 -05:00
parent 645411b59c
commit de0722b430
2 changed files with 54 additions and 18 deletions

View file

@ -1,15 +1,15 @@
use std::{collections::HashMap, option::Option, path::PathBuf};
use crisp::types::{Keyword, Symbol, Value};
use miette::{IntoDiagnostic, Result, miette};
use miette::{miette, IntoDiagnostic, Result};
use serde::{Deserialize, Serialize};
use sqlx::{
FromRow, Row, Sqlite, SqliteConnection, SqlitePool,
pool::PoolConnection, query, sqlite::SqliteRow,
pool::PoolConnection, query, sqlite::SqliteRow, Acquire, FromRow,
Row, Sqlite, SqliteConnection, SqlitePool,
};
use tracing::error;
use crate::{Slide, SlideBuilder, core::slide};
use crate::{core::slide, Slide, SlideBuilder};
use super::{
content::Content,
@ -407,6 +407,19 @@ impl Model<Song> {
}
}
}
pub async fn remove_from_db(
&mut self,
db: &mut SqlitePool,
id: i32,
) -> Result<()> {
let db = db.acquire().await.expect("probs");
query!("delete from songs where id = $1", id)
.execute(&mut db.detach())
.await
.into_diagnostic()
.map(|_| ())
}
}
pub async fn update_song_in_db(

View file

@ -1,34 +1,34 @@
use std::collections::HashMap;
use cosmic::{
Element, Task,
iced::{
alignment::Vertical, clipboard::dnd::DndAction,
futures::FutureExt, Background, Border, Color, Length,
Background, Border, Color, Length, alignment::Vertical,
clipboard::dnd::DndAction, futures::FutureExt,
},
iced_core::widget::tree::State,
iced_widget::{column, row as rowm, text as textm},
theme,
widget::{
button, container, context_menu, horizontal_space, icon,
Container, DndSource, Space, button, container, context_menu,
horizontal_space, icon,
menu::{self, Action as MenuAction},
mouse_area, responsive, row, scrollable, text, text_input,
Container, DndSource, Space,
},
Element, Task,
};
use miette::{IntoDiagnostic, Result};
use rapidfuzz::distance::levenshtein;
use sqlx::{pool::PoolConnection, Sqlite, SqlitePool};
use sqlx::{Sqlite, SqlitePool, pool::PoolConnection};
use tracing::{debug, error, warn};
use crate::core::{
content::Content,
images::{update_image_in_db, Image},
images::{Image, update_image_in_db},
model::{LibraryKind, Model},
presentations::{update_presentation_in_db, Presentation},
presentations::{Presentation, update_presentation_in_db},
service_items::ServiceItem,
songs::{update_song_in_db, Song},
videos::{update_video_in_db, Video},
songs::{Song, update_song_in_db},
videos::{Video, update_video_in_db},
};
#[derive(Debug, Clone)]
@ -132,11 +132,34 @@ impl<'a> Library {
Message::None => (),
Message::DeleteItem((kind, index)) => {
match kind {
LibraryKind::Song => todo!(),
LibraryKind::Video => todo!(),
LibraryKind::Image => todo!(),
LibraryKind::Song => {
if let Err(e) =
self.song_library.remove_item(index)
{
error!(?e);
}
}
LibraryKind::Video => {
if let Err(e) =
self.video_library.remove_item(index)
{
error!(?e);
}
}
LibraryKind::Image => {
if let Err(e) =
self.image_library.remove_item(index)
{
error!(?e);
}
}
LibraryKind::Presentation => {
self.presentation_library.remove_item(index);
if let Err(e) = self
.presentation_library
.remove_item(index)
{
error!(?e);
}
}
};
}