add series support
This commit is contained in:
parent
6a79f0c1ed
commit
a91fe9a0bb
11 changed files with 183 additions and 43 deletions
|
@ -57,6 +57,19 @@ impl Book {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn series_books(conn: &Connection, id: u64) -> Result<Vec<Book>, DataStoreError> {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT books.id, books.title, books.sort, books.path FROM series \
|
||||
INNER JOIN books_series_link ON series.id = books_series_link.series \
|
||||
INNER JOIN books ON books.id = books_series_link.book \
|
||||
WHERE books_series_link.series = (:id) \
|
||||
ORDER BY books.series_index",
|
||||
)?;
|
||||
let params = named_params! { ":id": id };
|
||||
let iter = stmt.query_map(params, Self::from_row)?;
|
||||
Ok(iter.filter_map(Result::ok).collect())
|
||||
}
|
||||
|
||||
pub fn recents(conn: &Connection, limit: u64) -> Result<Vec<Self>, DataStoreError> {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, title, sort, path FROM books ORDER BY timestamp DESC LIMIT (:limit)",
|
||||
|
@ -73,20 +86,10 @@ impl Book {
|
|||
}
|
||||
|
||||
pub fn has_previous_books(conn: &Connection, sort_title: &str) -> Result<bool, DataStoreError> {
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT Count(1) FROM books WHERE sort < (:sort_title) ORDER BY sort DESC")?;
|
||||
let params = named_params! { ":sort_title": sort_title};
|
||||
let count: u64 = stmt.query_row(params, |x| x.get(0))?;
|
||||
|
||||
Ok(count > 0)
|
||||
Pagination::has_prev_or_more(conn, "books", sort_title, &SortOrder::DESC)
|
||||
}
|
||||
|
||||
pub fn has_more_books(conn: &Connection, sort_title: &str) -> Result<bool, DataStoreError> {
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT Count(1) FROM books WHERE sort > (:sort_title) ORDER BY sort ASC")?;
|
||||
let params = named_params! { ":sort_title": sort_title};
|
||||
let count: u64 = stmt.query_row(params, |x| x.get(0))?;
|
||||
|
||||
Ok(count > 0)
|
||||
Pagination::has_prev_or_more(conn, "books", sort_title, &SortOrder::ASC)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue