2026-07-12 11:28:39 +07:00
|
|
|
//! SQLite-backed message log: per-session `messages.sqlite` storing chat
|
|
|
|
|
//! messages, blobs, and archive/summary metadata.
|
|
|
|
|
|
2026-07-12 01:25:52 +07:00
|
|
|
pub mod blobs;
|
2026-07-11 13:16:10 +07:00
|
|
|
pub mod query;
|
|
|
|
|
pub mod schema;
|
2026-07-11 23:45:13 +07:00
|
|
|
|
2026-07-12 01:25:52 +07:00
|
|
|
pub use blobs::store_blob;
|
2026-07-11 23:45:13 +07:00
|
|
|
pub use query::insert_message;
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// 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.
|
2026-07-11 23:45:13 +07:00
|
|
|
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)?;
|
|
|
|
|
schema::init_schema(&conn)?;
|
|
|
|
|
Ok(conn)
|
|
|
|
|
}
|