adding a remove from db function
This commit is contained in:
parent
de0722b430
commit
e2406b5462
6 changed files with 245 additions and 29 deletions
|
|
@ -168,6 +168,17 @@ impl Model<Image> {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn remove_from_db(
|
||||
db: PoolConnection<Sqlite>,
|
||||
id: i32,
|
||||
) -> Result<()> {
|
||||
query!("DELETE FROM images WHERE id = $1", id)
|
||||
.execute(&mut db.detach())
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn update_image_in_db(
|
||||
image: Image,
|
||||
db: PoolConnection<Sqlite>,
|
||||
|
|
|
|||
|
|
@ -263,6 +263,17 @@ impl Model<Presentation> {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn remove_from_db(
|
||||
db: PoolConnection<Sqlite>,
|
||||
id: i32,
|
||||
) -> Result<()> {
|
||||
query!("DELETE FROM presentations WHERE id = $1", id)
|
||||
.execute(&mut db.detach())
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn update_presentation_in_db(
|
||||
presentation: Presentation,
|
||||
db: PoolConnection<Sqlite>,
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ impl TryFrom<PathBuf> for Background {
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Couldn't canonicalize: {e} {:?}", path);
|
||||
// error!("Couldn't canonicalize: {e} {:?}", path);
|
||||
Err(ParseError::CannotCanonicalize)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -407,19 +407,17 @@ 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 remove_from_db(
|
||||
db: PoolConnection<Sqlite>,
|
||||
id: i32,
|
||||
) -> Result<()> {
|
||||
query!("DELETE FROM songs WHERE id = $1", id)
|
||||
.execute(&mut db.detach())
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn update_song_in_db(
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ use crisp::types::{Keyword, Symbol, Value};
|
|||
use miette::{IntoDiagnostic, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{
|
||||
Sqlite, SqliteConnection, SqlitePool, pool::PoolConnection,
|
||||
query, query_as,
|
||||
pool::PoolConnection, query, query_as, Sqlite, SqliteConnection,
|
||||
SqlitePool,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tracing::error;
|
||||
|
||||
#[derive(
|
||||
|
|
@ -35,6 +35,25 @@ impl From<&Video> for Value {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<PathBuf> for Video {
|
||||
fn from(value: PathBuf) -> Self {
|
||||
let title: String = value.file_name().map_or_else(|| "Video".into(), |filename| {
|
||||
filename.to_str().unwrap_or("Video").into()
|
||||
});
|
||||
Self {
|
||||
title,
|
||||
path: value,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Path> for Video {
|
||||
fn from(value: &Path) -> Self {
|
||||
Self::from(value.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl Content for Video {
|
||||
fn title(&self) -> String {
|
||||
self.title.clone()
|
||||
|
|
@ -205,6 +224,17 @@ impl Model<Video> {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn remove_from_db(
|
||||
db: PoolConnection<Sqlite>,
|
||||
id: i32,
|
||||
) -> Result<()> {
|
||||
query!("DELETE FROM videos WHERE id = $1", id)
|
||||
.execute(&mut db.detach())
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn update_video_in_db(
|
||||
video: Video,
|
||||
db: PoolConnection<Sqlite>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue