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//! The database is unencrypted and has no licensing or usage-gating table.
6//!
7//! - [`pool`] — opens the database and runs migrations (`connect`/`connect_in_memory`). The
8//! only supported way to get a `SqlitePool` in bhtune.
9//! - [`convert`] — maps `bhtune-core`'s `serde`-tagged enums to/from the `TEXT` columns
10//! SQLite stores them as.
11//! - [`models`] — typed row/repository APIs for every table created by the migration set.
12//! - [`seed`] — upserts the built-in DCS/PLC templates on startup.
13//! - [`backup`] — full-database export (`VACUUM INTO`) and restore, independent of any
14//! single table.
15//! - [`error`] — the crate's error type, [`error::DbError`].
16//!
17//! Tables: `dcs_templates`, `loops`, `tune_runs`, `tune_samples`, `tune_results`,
18//! `tune_mv_actuations`, `tune_writes`, `settings` — see the embedded baseline migration for
19//! the full schema and the rationale behind each design decision (nullability, JSON-vs-columns,
20//! cascade rules).
21
22#![cfg_attr(
23 test,
24 allow(
25 clippy::unwrap_used,
26 clippy::expect_used,
27 clippy::panic,
28 reason = "unit tests may use unwrap, expect, and panic; production code must return typed errors"
29 )
30)]
31
32pub mod backup;
33pub mod convert;
34pub mod error;
35pub mod models;
36pub mod pool;
37pub mod seed;
38
39pub use backup::{RestoreOutcome, backup_to, restore_from};
40pub use error::{DbError, DbResult};
41pub use models::DemoSessionRow;
42pub use pool::{connect, connect_in_memory, connect_read_only, database_path};
43pub use seed::{SeedOutcome, SeedResult, seed_builtin_templates, seed_templates};
44// Every `models`/`pool` function already takes/returns `sqlx::SqlitePool` in its public
45// signature, so re-exporting the type here lets downstream crates (e.g. the `bhtune` package) name
46// and hold onto a pool without adding their own direct `sqlx` dependency that would then
47// need to independently track the exact same version this crate uses internally.
48pub use sqlx::SqlitePool;