Skip to main content

Db

Struct Db 

Source
pub struct Db {
    pool: SqlitePool,
}

Fields§

§pool: SqlitePool

Implementations§

Source§

impl Db

Source

pub fn new(database: &Database) -> Self

Source

pub fn register_library(&self, path: &str, name: &str) -> Result<i64, Error>

Source

pub fn get_library_by_path(&self, path: &str) -> Result<Option<i64>, Error>

Source

fn parse_zoom_mode(json: Option<&String>) -> Option<ZoomMode>

Source

fn parse_scroll_mode(json: Option<&String>) -> Option<ScrollMode>

Source

fn parse_text_align(json: Option<&String>) -> Option<TextAlign>

Source

fn parse_cropping_margins(json: Option<&String>) -> Option<CroppingMargins>

Source

fn parse_page_names(json: Option<&String>) -> BTreeMap<usize, String>

Source

fn parse_bookmarks(json: Option<&String>) -> BTreeSet<usize>

Source

fn parse_annotations(json: Option<&String>) -> Vec<Annotation>

Source

fn parse_page_offset(x: Option<i64>, y: Option<i64>) -> Option<Point>

Source

fn extract_authors(authors: Option<String>) -> String

Source

fn extract_categories(categories: Option<String>) -> BTreeSet<String>

Source

async fn fetch_toc_entries_for_book( pool: &SqlitePool, library_id: i64, fingerprint: &str, ) -> Result<Vec<TocEntryRow>, Error>

Source

fn stored_book_row_to_info( row: StoredBookRow, toc: Option<Vec<SimpleTocEntry>>, ) -> Result<Info, Error>

Source

async fn insert_toc_entries( conn: &mut SqliteConnection, book_fingerprint: &str, entries: &[SimpleTocEntry], parent_id: Option<Uuid7>, ) -> Result<(), Error>

Source

async fn fetch_all_toc_entries( pool: &SqlitePool, library_id: i64, ) -> Result<HashMap<String, Vec<TocEntryRow>>, Error>

Source

pub fn get_all_books(&self, library_id: i64) -> Result<Vec<Info>, Error>

Source

pub fn get_book_by_path( &self, library_id: i64, path: &Path, ) -> Result<Option<Info>, Error>

Source

pub fn get_book_by_fingerprint( &self, library_id: i64, fp: Fp, ) -> Result<Option<Info>, Error>

Source

pub fn batch_get_books_by_fingerprints( &self, library_id: i64, fps: &[Fp], ) -> Result<FxHashMap<Fp, Info>, Error>

Fetches complete Info for multiple fingerprints in a single library using one pooled connection. Missing fingerprints are silently skipped.

Used by import() to retrieve book metadata (title, authors, reading state, etc.) for all fingerprint relocations in one batch, before re-inserting under new FPs.

Source

pub fn count_books(&self, library_id: i64) -> Result<usize, Error>

Source

pub fn list_books_under_prefix( &self, library_id: i64, prefix: &Path, ) -> Result<Vec<Info>, Error>

Source

pub fn most_recently_opened_reading_book( &self, library_id: i64, ) -> Result<Option<Info>, Error>

Source

pub fn compute_sort_keys(&self, library_id: i64) -> Result<(), Error>

Recomputes sort ranks for all books in a library and writes them to the five pre-computed sort columns (sort_title, sort_author, sort_filepath, sort_filename, sort_series).

§Sparse rank scheme

Ranks are stored as multiples of 1000 rather than consecutive integers (1 → 1 000, 2 → 2 000, …). The gaps allow a single newly added book to be inserted cheaply via Self::insert_sort_rank: instead of shifting every book above the insertion point, the new book is assigned the midpoint between its two neighbours — a single UPDATE.

A full recompute is only needed after bulk changes (i.e. after import()). It also restores uniform gaps whenever they have been partially exhausted by many consecutive single-book insertions.

Source

pub fn insert_sort_rank( &self, library_id: i64, fp: Fp, info: &Info, ) -> Result<(), Error>

Inserts sort ranks for a single newly-added book without recomputing ranks for the entire library.

§How it works

Because Self::compute_sort_keys stores ranks as multiples of SORT_RANK_STRIDE (1 000), there is always a gap between adjacent books. For each sort column this method:

  1. Fetches only the two lightweight fields needed to compare the new book’s sort key — e.g. (book_fingerprint, title, sort_title) for the title column — ordered by the existing rank. No full Info load is required.
  2. Binary-searches the sorted list to find the insertion position using the same comparator as sorter(method).
  3. Assigns the midpoint between the two neighbouring ranks to the new book (e.g. between rank 3 000 and 4 000 → 3 500).

If any column has exhausted its gaps (two neighbours whose ranks differ by at most 1), it falls back to a full Self::compute_sort_keys recompute to restore uniform gaps for that library.

Source

fn try_insert_sort_rank( &self, library_id: i64, fp_str: &str, info: &Info, ) -> Result<bool, Error>

Attempts to insert sort ranks for a single book by midpoint assignment.

Returns true if any column has gaps too small to split (i.e. a full recompute is needed), false if all ranks were assigned successfully.

Source

fn resolve_title_rank( &self, library_id: i64, fp_str: &str, info: &Info, ) -> Result<Option<i64>, Error>

Source

fn resolve_author_rank( &self, library_id: i64, fp_str: &str, info: &Info, ) -> Result<Option<i64>, Error>

Source

fn resolve_filepath_rank( &self, library_id: i64, fp_str: &str, info: &Info, ) -> Result<Option<i64>, Error>

Source

fn resolve_filename_rank( &self, library_id: i64, fp_str: &str, info: &Info, ) -> Result<Option<i64>, Error>

Source

fn resolve_series_rank( &self, library_id: i64, fp_str: &str, info: &Info, ) -> Result<Option<i64>, Error>

Source

fn fetch_title_sort_rows( &self, library_id: i64, fp_str: &str, ) -> Result<Vec<TitleSortRow>, Error>

Source

fn fetch_author_sort_rows( &self, library_id: i64, fp_str: &str, ) -> Result<Vec<AuthorSortRow>, Error>

Source

fn fetch_filepath_sort_rows( &self, library_id: i64, fp_str: &str, ) -> Result<Vec<FilePathSortRow>, Error>

Source

fn fetch_filename_sort_rows( &self, library_id: i64, fp_str: &str, ) -> Result<Vec<FileNameSortRow>, Error>

Source

fn fetch_series_sort_rows( &self, library_id: i64, fp_str: &str, ) -> Result<Vec<SeriesSortRow>, Error>

Source

pub fn page_books( &self, library_id: i64, prefix: &Path, sort_method: SortMethod, reverse: bool, limit: i64, offset: i64, ) -> Result<(Vec<Info>, i64), Error>

Returns a page of books under prefix, sorted by sort_method, along with the total number of matching books.

Uses untyped sqlx::query_as so the ORDER BY column can be selected dynamically.

Source

pub fn list_directories_under_prefix( &self, library_id: i64, prefix: &Path, ) -> Result<BTreeSet<PathBuf>, Error>

Source

pub fn insert_book( &self, library_id: i64, fp: Fp, info: &Info, ) -> Result<(), Error>

Source

pub fn update_book( &self, library_id: i64, fp: Fp, info: &Info, ) -> Result<(), Error>

Rewrites the stored metadata for one book and its library-specific path fields.

Source

pub fn delete_reading_state(&self, fp: Fp) -> Result<(), Error>

Source

pub fn delete_book(&self, library_id: i64, fp: Fp) -> Result<(), Error>

Source

pub fn get_thumbnail(&self, fp: Fp) -> Result<Option<Vec<u8>>, Error>

Source

pub fn get_thumbnail_by_path( &self, library_id: i64, path: &Path, ) -> Result<Option<Vec<u8>>, Error>

Source

pub fn save_thumbnail(&self, fp: Fp, data: &[u8]) -> Result<(), Error>

Source

pub fn delete_thumbnail(&self, fp: Fp) -> Result<(), Error>

Source

pub fn batch_delete_thumbnails(&self, fps: &[Fp]) -> Result<(), Error>

Source

pub fn move_thumbnail(&self, from_fp: Fp, to_fp: Fp) -> Result<(), Error>

Source

pub fn batch_move_thumbnails(&self, moves: &[(Fp, Fp)]) -> Result<(), Error>

Source

pub fn save_reading_state( &self, fp: Fp, reader_info: &ReaderInfo, ) -> Result<(), Error>

Source

pub fn save_toc(&self, fp: Fp, toc: &[SimpleTocEntry]) -> Result<(), Error>

Source

pub fn batch_insert_books( &self, library_id: i64, books: &[(Fp, &Info)], ) -> Result<(), Error>

Source

pub fn batch_update_books( &self, library_id: i64, books: &[(Fp, &Info)], ) -> Result<(), Error>

Source

pub fn list_book_handles( &self, library_id: i64, ) -> Result<Vec<(Fp, PathBuf)>, Error>

Returns (fingerprint, path) pairs for every book currently linked to a library.

Source

pub fn update_book_path( &self, library_id: i64, fp: Fp, rel_path: &Path, abs_path: &Path, ) -> Result<(), Error>

Updates both the relative and absolute path of a book in a single transaction. No-op if the book is not found in the library.

Source

pub fn batch_update_book_paths( &self, library_id: i64, updates: &[(Fp, PathBuf, PathBuf)], ) -> Result<(), Error>

Updates relative and absolute paths for multiple books in a single transaction, with one combined UPDATE per entry. Used by import() after directory scanning to record the final locations of books that were moved or renamed on disk.

Source

pub fn batch_delete_books( &self, library_id: i64, fps: &[Fp], ) -> Result<(), Error>

Source

pub fn delete_books_with_disallowed_kinds( &self, library_id: i64, allowed_kinds: &FxHashSet<FileExtension>, ) -> Result<Vec<Fp>, Error>

Deletes all library_books rows for this library whose file_kind is not in allowed_kinds, cleans up orphaned books rows, and returns the fingerprints of removed entries so callers can purge thumbnails.

Called at the start of every import so that books whose kind was later removed from allowed_kinds do not persist in the database.

Trait Implementations§

Source§

impl Clone for Db

Source§

fn clone(&self) -> Db

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Db

§

impl !RefUnwindSafe for Db

§

impl Send for Db

§

impl Sync for Db

§

impl Unpin for Db

§

impl UnsafeUnpin for Db

§

impl !UnwindSafe for Db

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more