proper error handling
This commit is contained in:
parent
687c33829f
commit
ac7b0e7e88
15 changed files with 245 additions and 25 deletions
|
@ -8,7 +8,7 @@ use super::{
|
|||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Book {
|
||||
pub id: i32,
|
||||
pub id: u64,
|
||||
pub title: String,
|
||||
pub sort: String,
|
||||
pub path: String,
|
||||
|
@ -24,12 +24,12 @@ impl Book {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn books(
|
||||
pub fn multiple(
|
||||
conn: &Connection,
|
||||
limit: u64,
|
||||
cursor: Option<&str>,
|
||||
sort_order: SortOrder,
|
||||
) -> Result<Vec<Book>, DataStoreError> {
|
||||
) -> Result<Vec<Self>, DataStoreError> {
|
||||
let pagination = Pagination::new("sort", cursor, limit, sort_order);
|
||||
pagination.paginate(
|
||||
conn,
|
||||
|
@ -45,7 +45,7 @@ impl Book {
|
|||
limit: u64,
|
||||
cursor: Option<&str>,
|
||||
sort_order: SortOrder,
|
||||
) -> Result<Vec<Book>, DataStoreError> {
|
||||
) -> Result<Vec<Self>, DataStoreError> {
|
||||
let pagination = Pagination::new("books.sort", cursor, limit, sort_order);
|
||||
pagination.paginate(
|
||||
conn,
|
||||
|
@ -57,7 +57,7 @@ impl Book {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn recents(conn: &Connection, limit: u64) -> Result<Vec<Book>, DataStoreError> {
|
||||
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)",
|
||||
)?;
|
||||
|
@ -66,7 +66,7 @@ impl Book {
|
|||
Ok(iter.filter_map(Result::ok).collect())
|
||||
}
|
||||
|
||||
pub fn scalar_book(conn: &Connection, id: u64) -> Result<Book, DataStoreError> {
|
||||
pub fn scalar_book(conn: &Connection, id: u64) -> Result<Self, DataStoreError> {
|
||||
let mut stmt = conn.prepare("SELECT id, title, sort, path FROM books WHERE id = (:id)")?;
|
||||
let params = named_params! { ":id": id };
|
||||
Ok(stmt.query_row(params, Self::from_row)?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue