proper error handling
This commit is contained in:
parent
687c33829f
commit
ac7b0e7e88
15 changed files with 245 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
use rusqlite::{Connection, Row};
|
||||
use rusqlite::{named_params, Connection, Row};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{
|
||||
|
@ -8,7 +8,7 @@ use super::{
|
|||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Author {
|
||||
pub id: i32,
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub sort: String,
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ impl Author {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn authors(
|
||||
pub fn multiple(
|
||||
conn: &Connection,
|
||||
limit: u64,
|
||||
cursor: Option<&str>,
|
||||
sort_order: SortOrder,
|
||||
) -> Result<Vec<Author>, DataStoreError> {
|
||||
) -> Result<Vec<Self>, DataStoreError> {
|
||||
let pagination = Pagination::new("sort", cursor, limit, sort_order);
|
||||
pagination.paginate(
|
||||
conn,
|
||||
|
@ -36,4 +36,14 @@ impl Author {
|
|||
Self::from_row,
|
||||
)
|
||||
}
|
||||
|
||||
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 \
|
||||
INNER JOIN books_authors_link ON authors.id = books_authors_link.author \
|
||||
WHERE books_authors_link.book = (: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