chore: fix all 702 clippy warnings across codebase - auto-fix 475 via cargo clippy --fix - fix remaining 227 manually: uninlined_format_args, redundant_closure, match_same_arms, underscore_binding, format_push_string, items_after_statements, needless_pass_by_value, clone_on_copy, case_sensitive_extension, single_match/let-else, write_with_newline, and other clippy lints
30 lines
1011 B
Rust
30 lines
1011 B
Rust
//! SQLite-backed message log: per-session `messages.sqlite` storing chat
|
|
//! messages, blobs, and archive/summary metadata.
|
|
|
|
pub mod blobs;
|
|
pub mod query;
|
|
pub mod schema;
|
|
|
|
pub use blobs::store_blob;
|
|
pub use query::insert_message;
|
|
|
|
/// Open (creating if needed) a session's `messages.sqlite` and ensure its
|
|
/// schema is initialized.
|
|
///
|
|
/// Flow: resolve `<session_dir>/messages.sqlite` → create parent dirs →
|
|
/// open a `SQLite` connection → run `schema::init_schema`.
|
|
///
|
|
/// Return: an open, schema-ready `Connection`, or an error if any step
|
|
/// fails.
|
|
pub fn open_or_create(session_dir: &std::path::Path) -> anyhow::Result<rusqlite::Connection> {
|
|
let path = session_dir.join("messages.sqlite");
|
|
if let Some(parent) = path.parent() {
|
|
std::fs::create_dir_all(parent)?;
|
|
}
|
|
let conn = rusqlite::Connection::open(&path)?;
|
|
conn.execute_batch("PRAGMA journal_mode = WAL;")?;
|
|
conn.execute_batch("PRAGMA busy_timeout = 5000;")?;
|
|
schema::init_schema(&conn)?;
|
|
Ok(conn)
|
|
}
|