summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/mod.rs4
-rw-r--r--src/db/product.rs7
-rw-r--r--src/db/story.rs13
3 files changed, 23 insertions, 1 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs
index e44c9ad..51665a3 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -25,4 +25,8 @@ pub trait ProductDatabaseHandler {
) -> Result<Self, AppError>
where
Self: Sized;
+
+ async fn delete(pool: &SqlitePool, id: i64) -> Result<(), AppError>
+ where
+ Self: Sized;
}
diff --git a/src/db/product.rs b/src/db/product.rs
index 06217c0..c21734e 100644
--- a/src/db/product.rs
+++ b/src/db/product.rs
@@ -5,7 +5,6 @@ use sqlx::{QueryBuilder, Sqlite, SqlitePool, Transaction};
use crate::error::AppError;
-use super::producttag::ProductTag;
use super::tag::Tag;
use super::ProductDatabaseHandler;
@@ -50,6 +49,12 @@ impl Product {
}
Ok(product)
}
+
+ pub async fn delete(tx: &mut Transaction<'static, Sqlite>, pid: i64) -> Result<(), AppError> {
+ sqlx::query!("DELETE FROM producttag WHERE pid = $1", pid).execute(&mut **tx).await?;
+ sqlx::query!("DELETE FROM product WHERE id = $1", pid).execute(&mut **tx).await?;
+ Ok(())
+ }
}
pub trait ProductMarker {
diff --git a/src/db/story.rs b/src/db/story.rs
index 137c964..9e5fdb9 100644
--- a/src/db/story.rs
+++ b/src/db/story.rs
@@ -99,6 +99,19 @@ impl ProductDatabaseHandler for Story {
Ok(story)
}
+
+ async fn delete(pool: &SqlitePool, pid: i64) -> Result<(), AppError>
+ where
+ Self: Sized,
+ {
+ let mut tx = pool.begin().await?;
+ sqlx::query!("DELETE FROM story WHERE pid = $1", pid)
+ .execute(&mut *tx)
+ .await?;
+ Product::delete(&mut tx, pid).await?;
+ tx.commit().await?;
+ Ok(())
+ }
}
impl PageBuilder for Story {