bare bones calibre db reading
This commit is contained in:
commit
65e17fc55b
13 changed files with 790 additions and 0 deletions
38
calibre-db/src/data/author.rs
Normal file
38
calibre-db/src/data/author.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use rusqlite::{Connection, Row};
|
||||
|
||||
use super::{
|
||||
error::DataStoreError,
|
||||
pagination::{Pagination, SortOrder},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Author {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub sort: String,
|
||||
}
|
||||
|
||||
impl Author {
|
||||
fn from_row(row: &Row<'_>) -> Result<Self, rusqlite::Error> {
|
||||
Ok(Self {
|
||||
id: row.get(0)?,
|
||||
name: row.get(1)?,
|
||||
sort: row.get(2)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn authors(
|
||||
conn: &Connection,
|
||||
limit: u64,
|
||||
cursor: Option<&str>,
|
||||
sort_order: SortOrder,
|
||||
) -> Result<Vec<Author>, DataStoreError> {
|
||||
let pagination = Pagination::new("sort", cursor, limit, sort_order);
|
||||
pagination.paginate(
|
||||
conn,
|
||||
"SELECT id, name, sort FROM authors",
|
||||
&[],
|
||||
Self::from_row,
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue