Skip to main content

cadmus_core/library/db/
models.rs

1use crate::db::types::{FileSize, OptionalUuid7, UnixTimestamp, Uuid7};
2use crate::helpers::Fp;
3use sqlx::FromRow;
4use std::path::PathBuf;
5
6/// Database row for the books table
7#[derive(Debug, Clone, FromRow)]
8pub struct BookRow {
9    pub fingerprint: String,
10    pub title: String,
11    pub subtitle: String,
12    pub year: String,
13    pub language: String,
14    pub publisher: String,
15    pub series: String,
16    pub edition: String,
17    pub volume: String,
18    pub number: String,
19    pub identifier: String,
20    pub file_path: String,
21    pub absolute_path: String,
22    pub file_kind: String,
23    pub file_size: i64,
24    pub added_at: UnixTimestamp,
25}
26
27/// A book record loaded from the database at the start of an import scan.
28pub struct BookHandle {
29    pub fp: Fp,
30    pub relat: PathBuf,
31    pub abs: PathBuf,
32    pub mtime: Option<UnixTimestamp>,
33    pub file_size: Option<FileSize>,
34}
35
36/// A pending write that records a book's new paths and current mtime/size.
37///
38/// Accumulated during the scan and flushed to the database in a single
39/// batched transaction at the end, avoiding N individual fsyncs.
40pub struct PathUpdate {
41    pub fp: Fp,
42    pub relat: PathBuf,
43    pub abs: PathBuf,
44    pub mtime: Option<UnixTimestamp>,
45    pub file_size: Option<FileSize>,
46}
47
48/// Database row for the reading_states table
49#[derive(Debug, Clone, FromRow)]
50pub struct ReadingStateRow {
51    pub fingerprint: String,
52    pub opened: UnixTimestamp,
53    pub current_page: i64,
54    pub pages_count: i64,
55    pub finished: i64,
56    pub dithered: i64,
57    pub zoom_mode: Option<String>,
58    pub scroll_mode: Option<String>,
59    pub page_offset_x: Option<i64>,
60    pub page_offset_y: Option<i64>,
61    pub rotation: Option<i64>,
62    pub cropping_margins_json: Option<String>,
63    pub margin_width: Option<i64>,
64    pub screen_margin_width: Option<i64>,
65    pub font_family: Option<String>,
66    pub font_size: Option<f64>,
67    pub text_align: Option<String>,
68    pub line_height: Option<f64>,
69    pub contrast_exponent: Option<f64>,
70    pub contrast_gray: Option<f64>,
71    pub page_names_json: Option<String>,
72    pub bookmarks_json: Option<String>,
73    pub annotations_json: Option<String>,
74}
75
76/// Database row for the toc_entries table
77#[derive(Debug, Clone, FromRow)]
78pub struct TocEntryRow {
79    pub book_fingerprint: String,
80    pub id: Uuid7,
81    pub parent_id: OptionalUuid7,
82    pub position: i64,
83    pub title: String,
84    pub location_kind: String,
85    pub location_exact: Option<i64>,
86    pub location_uri: Option<String>,
87}