some more docs
This commit is contained in:
parent
1314320260
commit
41206abac1
29 changed files with 119 additions and 0 deletions
|
@ -283,6 +283,7 @@ impl Calibre {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// Tests for the calibre module.
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//! Data types and functions for interacting with the calibre database.
|
||||
pub mod author;
|
||||
pub mod book;
|
||||
pub mod error;
|
||||
|
|
|
@ -24,17 +24,23 @@ pub struct MultipleAuthorsError {
|
|||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching a book's author.
|
||||
pub enum BookAuthorError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareBookAuthor { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteBookAuthor { source: rusqlite::Error },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching a single author.
|
||||
pub enum ScalarAuthorError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareScalarAuthor { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteScalarAuthor { source: rusqlite::Error },
|
||||
}
|
||||
|
@ -52,6 +58,7 @@ pub struct MoreAuthorsError {
|
|||
}
|
||||
|
||||
impl Author {
|
||||
/// Create an author from a database row.
|
||||
fn from_row(row: &Row<'_>) -> Result<Self, rusqlite::Error> {
|
||||
Ok(Self {
|
||||
id: row.get(0)?,
|
||||
|
|
|
@ -39,25 +39,34 @@ pub struct AuthorBooksError {
|
|||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching a series' books.
|
||||
pub enum SeriesBookError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareSeriesBook { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteSeriesBook { source: rusqlite::Error },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching recent books.
|
||||
pub enum RecentBooksError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareRecentBooks { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteRecentBooks { source: rusqlite::Error },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching a single book.
|
||||
pub enum ScalarBookError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareScalarBook { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteScalarBook { source: rusqlite::Error },
|
||||
}
|
||||
|
@ -75,6 +84,7 @@ pub struct MoreBooksError {
|
|||
}
|
||||
|
||||
impl Book {
|
||||
/// Create a book from a database row.
|
||||
fn from_row(row: &Row<'_>) -> Result<Self, rusqlite::Error> {
|
||||
Ok(Self {
|
||||
id: row.get(0)?,
|
||||
|
|
|
@ -24,17 +24,23 @@ pub struct MultiplSeriesError {
|
|||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching a series' books.
|
||||
pub enum SeriesBooksError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareSeriesBooks { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteSeriesBooks { source: rusqlite::Error },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when fetching a single series.
|
||||
pub enum ScalarSeriesError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareScalarSeries { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteScalarSeries { source: rusqlite::Error },
|
||||
}
|
||||
|
@ -52,6 +58,7 @@ pub struct MoreSeriesError {
|
|||
}
|
||||
|
||||
impl Series {
|
||||
/// Create a series from a database row.
|
||||
fn from_row(row: &Row<'_>) -> Result<Self, rusqlite::Error> {
|
||||
Ok(Self {
|
||||
id: row.get(0)?,
|
||||
|
|
|
@ -35,39 +35,54 @@ const SEARCH_INIT_QUERY: &str = "INSERT INTO search.fts(book_id, data)
|
|||
GROUP BY b.id";
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when ensuring the search database is available.
|
||||
pub enum EnsureSearchDbError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareEnsureSearch { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteEnsureSearch { source: rusqlite::Error },
|
||||
/// A failure to attach the database.
|
||||
#[snafu(display("Failed to attach database."))]
|
||||
Attach { source: AttachError },
|
||||
/// A failure to initialize the database.
|
||||
#[snafu(display("Failed to initialize database."))]
|
||||
Init { source: InitError },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when attaching the search database.
|
||||
pub enum AttachError {
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteAttach { source: rusqlite::Error },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when initializing the search database.
|
||||
pub enum InitError {
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareInit { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteInit { source: rusqlite::Error },
|
||||
}
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
/// Errors that can occur when searching.
|
||||
pub enum SearchError {
|
||||
/// A failure to ensure the search database is initialized.
|
||||
#[snafu(display("Failed ensure the search db is initialized."))]
|
||||
EnsureDb { source: EnsureSearchDbError },
|
||||
/// A failure to get a connection from the pool.
|
||||
#[snafu(display("Failed to get connection from pool."))]
|
||||
Connection { source: r2d2::Error },
|
||||
/// A failure to prepare the SQL statement.
|
||||
#[snafu(display("Failed to prepare statement."))]
|
||||
PrepareSearch { source: rusqlite::Error },
|
||||
/// A failure to execute the SQL statement.
|
||||
#[snafu(display("Failed to execute statement."))]
|
||||
ExecuteSearch { source: rusqlite::Error },
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue