bit of documentation

This commit is contained in:
Sebastian Hugentobler 2024-05-10 14:25:18 +02:00
parent a41dcab889
commit 870f457f1b
Signed by: shu
GPG key ID: BB32CF3CA052C2F0
47 changed files with 341 additions and 80 deletions

View file

@ -1,3 +1,5 @@
//! Series data.
use rusqlite::{named_params, Connection, Row};
use serde::Serialize;
@ -6,10 +8,14 @@ use super::{
pagination::{Pagination, SortOrder},
};
/// Series in calibre.
#[derive(Debug, Clone, Serialize)]
pub struct Series {
/// Id in database.
pub id: u64,
/// Series name.
pub name: String,
/// Series name for sorting.
pub sort: String,
}
@ -22,6 +28,8 @@ impl Series {
})
}
/// Fetch series data from calibre, starting at `cursor`, fetching up to an amount of `limit` and
/// ordering by `sort_order`.
pub fn multiple(
conn: &Connection,
limit: u64,
@ -37,12 +45,14 @@ impl Series {
)
}
/// Fetch a single series with id `id`.
pub fn scalar_series(conn: &Connection, id: u64) -> Result<Self, DataStoreError> {
let mut stmt = conn.prepare("SELECT id, name, sort FROM series WHERE id = (:id)")?;
let params = named_params! { ":id": id };
Ok(stmt.query_row(params, Self::from_row)?)
}
/// Get the series a book with id `id` is in, as well as the book's position within the series.
pub fn book_series(
conn: &Connection,
book_id: u64,
@ -68,10 +78,12 @@ impl Series {
}
}
/// Check if there are more series before the specified cursor.
pub fn has_previous_series(conn: &Connection, sort_name: &str) -> Result<bool, DataStoreError> {
Pagination::has_prev_or_more(conn, "series", sort_name, &SortOrder::DESC)
}
/// Check if there are more series after the specified cursor.
pub fn has_more_series(conn: &Connection, sort_name: &str) -> Result<bool, DataStoreError> {
Pagination::has_prev_or_more(conn, "series", sort_name, &SortOrder::ASC)
}