bhtune_db/lib.rs
1//! `bhtune-db` — persistence.
2//!
3//! A single, plain, open SQLite database (via `sqlx`, WAL mode + busy timeout + foreign keys
4//! enforced) holds everything: DCS/PLC templates, loop configuration, and tune run history.
5//! There is deliberately no encryption and no licensing/usage-gating table — see AGENTS.md
6//! for why.
7//!
8//! - [`pool`] — opens the database and runs migrations (`connect`/`connect_in_memory`). The
9//! only supported way to get a `SqlitePool` in bhtune.
10//! - [`convert`] — maps `bhtune-core`'s `serde`-tagged enums to/from the `TEXT` columns
11//! SQLite stores them as.
12//! - [`models`] — typed row/repository APIs for every table created by the migration set.
13//! - [`seed`] — upserts the built-in DCS/PLC templates on startup.
14//! - [`backup`] — full-database export (`VACUUM INTO`) and restore, independent of any
15//! single table.
16//! - [`error`] — the crate's error type, [`error::DbError`].
17//!
18//! Tables: `dcs_templates`, `loops`, `tune_runs`, `tune_samples`, `tune_results`,
19//! `tune_mv_actuations`, `tune_writes`, `settings` — see the migration files for the full
20//! schema and the rationale behind each design decision (nullability, JSON-vs-columns,
21//! cascade rules).
22
23pub mod backup;
24pub mod convert;
25pub mod error;
26pub mod models;
27pub mod pool;
28pub mod seed;
29
30pub use backup::{RestoreOutcome, backup_to, restore_from};
31pub use error::{DbError, DbResult};
32pub use models::DemoSessionRow;
33pub use pool::{connect, connect_in_memory};
34pub use seed::{SeedOutcome, SeedResult, seed_builtin_templates, seed_templates};
35// Every `models`/`pool` function already takes/returns `sqlx::SqlitePool` in its public
36// signature, so re-exporting the type here lets downstream crates (e.g. `bhtune-cli`) name
37// and hold onto a pool without adding their own direct `sqlx` dependency that would then
38// need to independently track the exact same version this crate uses internally.
39pub use sqlx::SqlitePool;