diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2024-10-30 17:04:26 +0100 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2024-10-30 17:04:26 +0100 |
| commit | 61f784a5fb437489d5dd3f629618d49279ff15a5 (patch) | |
| tree | d92110ca3016c6c1417085d0a8fb9d2ec894a468 /src/db/story.rs | |
| parent | 977c93ef0568aa488c226915d14e6f164519fd98 (diff) | |
Feat: Add db handler method to get all records from table + implement for story
Diffstat (limited to 'src/db/story.rs')
| -rw-r--r-- | src/db/story.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/db/story.rs b/src/db/story.rs index 10fc49b..7bc5577 100644 --- a/src/db/story.rs +++ b/src/db/story.rs @@ -1,3 +1,10 @@ +use axum::async_trait; +use sqlx::SqlitePool; + +use crate::error::AppError; + +use super::DatabaseHandler; + #[derive(Debug, serde::Serialize, sqlx::FromRow)] pub struct Story { pub id: i64, @@ -6,3 +13,15 @@ pub struct Story { pub epub: Vec<u8>, pub pid: i64, } + +#[async_trait] +impl DatabaseHandler for Story { + async fn get_all(pool: SqlitePool) -> Result<Vec<Self>, AppError> + where + Self: Sized, + { + Ok(sqlx::query_as!(Story, "SELECT * FROM story") + .fetch_all(&pool) + .await?) + } +} |
