1mod migrations;
8mod project_db;
9mod app_db;
10
11pub use app_db::{AppDb, RecentProject};
12pub use project_db::{BaselineRecord, ClassificationRecord, ProjectDb, ScanHistoryRecord, SearchResult};
13
14use rusqlite::Connection;
15use thiserror::Error;
16
17#[derive(Error, Debug)]
19pub enum DbError {
20 #[error("SQLite error: {0}")]
22 Sqlite(#[from] rusqlite::Error),
23
24 #[error("Migration failed: {0}")]
26 Migration(String),
27
28 #[error("IO error: {0}")]
30 Io(#[from] std::io::Error),
31}
32
33pub type DbResult<T> = Result<T, DbError>;
34
35pub fn apply_pragmas(conn: &Connection) -> DbResult<()> {
37 conn.execute_batch(
38 "PRAGMA journal_mode = WAL;
39 PRAGMA synchronous = NORMAL;
40 PRAGMA wal_autocheckpoint = 1000;
41 PRAGMA busy_timeout = 5000;
42 PRAGMA cache_size = -64000;
43 PRAGMA foreign_keys = ON;
44 PRAGMA temp_store = MEMORY;",
45 )?;
46 Ok(())
47}
48
49#[cfg(test)]
50mod tests;