paginated authors
This commit is contained in:
parent
352d4e0a7a
commit
ead3672570
12 changed files with 175 additions and 23 deletions
|
@ -26,9 +26,9 @@ impl Author {
|
|||
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, name, sort FROM authors",
|
||||
|
@ -46,4 +46,25 @@ impl Author {
|
|||
let params = named_params! { ":id": id };
|
||||
Ok(stmt.query_row(params, Self::from_row)?)
|
||||
}
|
||||
|
||||
pub fn has_previous_authors(
|
||||
conn: &Connection,
|
||||
sort_name: &str,
|
||||
) -> Result<bool, DataStoreError> {
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT Count(1) FROM authors WHERE sort < (:sort_name) ORDER BY sort DESC")?;
|
||||
let params = named_params! { ":sort_name": sort_name };
|
||||
let count: u64 = stmt.query_row(params, |x| x.get(0))?;
|
||||
|
||||
Ok(count > 0)
|
||||
}
|
||||
|
||||
pub fn has_more_authors(conn: &Connection, sort_name: &str) -> Result<bool, DataStoreError> {
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT Count(1) FROM authors WHERE sort > (:sort_name) ORDER BY sort ASC")?;
|
||||
let params = named_params! { ":sort_name": sort_name };
|
||||
let count: u64 = stmt.query_row(params, |x| x.get(0))?;
|
||||
|
||||
Ok(count > 0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue