Skip to main content

hardy_sqlite_storage/
lib.rs

1/*!
2SQLite-backed metadata storage for the Hardy BPA.
3
4This crate provides a persistent [`MetadataStorage`](hardy_bpa::storage::MetadataStorage)
5implementation that stores bundle metadata in a SQLite database. It handles
6schema migrations, connection pooling, serialized write access, and the
7startup recovery protocol (mark-unconfirmed / confirm / sweep).
8
9# Key types
10
11- [`Config`] -- database directory and filename settings (serde-deserializable).
12- [`new()`] -- constructs an `Arc<dyn MetadataStorage>` ready for use by the BPA.
13*/
14
15mod config;
16mod migrate;
17mod storage;
18
19pub use config::Config;
20
21use trace_err::*;
22use tracing::{error, info, warn};
23
24#[cfg(feature = "instrument")]
25use tracing::instrument;
26
27use rusqlite::OptionalExtension;
28
29/// Creates a new SQLite metadata storage instance.
30///
31/// Opens (or creates) the database specified by `config`, runs schema migrations
32/// when `upgrade` is `true`, and returns the storage behind an `Arc<dyn MetadataStorage>`.
33pub fn new(
34    config: &config::Config,
35    upgrade: bool,
36) -> std::sync::Arc<dyn hardy_bpa::storage::MetadataStorage> {
37    std::sync::Arc::new(storage::Storage::new(config, upgrade))
38}