summaryrefslogtreecommitdiff
path: root/src/db/story.rs
blob: 7bc55771f191fb799692f399ecdf4d700d91f976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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,
    pub language: String,
    pub pdf: Vec<u8>,
    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?)
    }
}