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 @@
//! Author data.
use rusqlite::{named_params, Connection, Row};
use serde::Serialize;
@ -6,10 +8,14 @@ use super::{
pagination::{Pagination, SortOrder},
};
/// Author in calibre.
#[derive(Debug, Clone, Serialize)]
pub struct Author {
/// Id in database.
pub id: u64,
/// Full name.
pub name: String,
/// Full name for sorting.
pub sort: String,
}
@ -22,6 +28,8 @@ impl Author {
})
}
/// Fetch author 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,6 +45,7 @@ impl Author {
)
}
/// Get the author to a book with id `id`.
pub fn book_author(conn: &Connection, id: u64) -> Result<Self, DataStoreError> {
let mut stmt = conn.prepare(
"SELECT authors.id, authors.name, authors.sort FROM authors \
@ -47,12 +56,14 @@ impl Author {
Ok(stmt.query_row(params, Self::from_row)?)
}
/// Fetch a single author with id `id`.
pub fn scalar_author(conn: &Connection, id: u64) -> Result<Self, DataStoreError> {
let mut stmt = conn.prepare("SELECT id, name, sort FROM authors WHERE id = (:id)")?;
let params = named_params! { ":id": id };
Ok(stmt.query_row(params, Self::from_row)?)
}
/// Check if there are more authors before the specified cursor.
pub fn has_previous_authors(
conn: &Connection,
sort_name: &str,
@ -60,6 +71,7 @@ impl Author {
Pagination::has_prev_or_more(conn, "authors", sort_name, &SortOrder::DESC)
}
/// Check if there are more authors after the specified cursor.
pub fn has_more_authors(conn: &Connection, sort_name: &str) -> Result<bool, DataStoreError> {
Pagination::has_prev_or_more(conn, "authors", sort_name, &SortOrder::ASC)
}