add series support

This commit is contained in:
Sebastian Hugentobler 2024-05-06 16:25:15 +02:00
parent 6a79f0c1ed
commit a91fe9a0bb
Signed by: shu
GPG key ID: BB32CF3CA052C2F0
11 changed files with 183 additions and 43 deletions

View file

@ -26,17 +26,23 @@ impl Series {
conn: &Connection,
limit: u64,
cursor: Option<&str>,
sort_order: SortOrder,
sort_order: &SortOrder,
) -> Result<Vec<Self>, DataStoreError> {
let pagination = Pagination::new("sort", cursor, limit, sort_order);
let pagination = Pagination::new("sort", cursor, limit, *sort_order);
pagination.paginate(
conn,
"SELECT id, title, sort, path FROM series",
"SELECT id, name, sort FROM series",
&[],
Self::from_row,
)
}
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)?)
}
pub fn book_series(
conn: &Connection,
book_id: u64,
@ -61,4 +67,12 @@ impl Series {
Err(e) => Err(DataStoreError::SqliteError(e)),
}
}
pub fn has_previous_series(conn: &Connection, sort_name: &str) -> Result<bool, DataStoreError> {
Pagination::has_prev_or_more(conn, "series", sort_name, &SortOrder::DESC)
}
pub fn has_more_series(conn: &Connection, sort_name: &str) -> Result<bool, DataStoreError> {
Pagination::has_prev_or_more(conn, "series", sort_name, &SortOrder::ASC)
}
}