pub struct Store { /* private fields */ }Expand description
SQLite-backed session store.
Wraps rusqlite::Connection in a Mutex so the store is Send + Sync
and can be shared across threads without the caller needing to add their
own interior mutability.
The connection is opened in WAL mode with synchronous=NORMAL for
significantly better throughput on the agent hot path. Prepared
statements are cached across calls.
Implementations§
Source§impl Store
impl Store
pub fn open(path: &str) -> Result<Store, String>
Sourcepub fn journal_mode(&self) -> Result<String, String>
pub fn journal_mode(&self) -> Result<String, String>
Returns the current journal_mode PRAGMA value (e.g. “wal”).
Primarily used by tests to confirm WAL is active.
pub fn log_tool( &self, session: &str, name: &str, args: &str, result: &str, duration_us: u64, ) -> Result<(), String>
pub fn load(&self, session: &str) -> Result<Vec<Message>, String>
Sourcepub fn append(&self, session: &str, msg: &Message) -> Result<(), String>
pub fn append(&self, session: &str, msg: &Message) -> Result<(), String>
Append a single message. Uses a single INSERT…SELECT to compute the
next idx in one roundtrip instead of a separate SELECT + INSERT.
Sourcepub fn append_many(
&self,
session: &str,
messages: &[Message],
) -> Result<(), String>
pub fn append_many( &self, session: &str, messages: &[Message], ) -> Result<(), String>
Append many messages in a single transaction. Reduces fsync cost from 2+N per turn down to 1.
Sourcepub fn with_transaction<F, T>(&self, f: F) -> Result<T, String>
pub fn with_transaction<F, T>(&self, f: F) -> Result<T, String>
Run an arbitrary closure inside a single BEGIN/COMMIT transaction.
The closure receives a borrowed rusqlite::Transaction and can issue
multiple writes that will all commit together (or roll back on error).
pub fn clear(&self, session: &str) -> Result<(), String>
Sourcepub fn stats(
&self,
session: &str,
) -> Result<Vec<(String, i64, i64, i64)>, String>
pub fn stats( &self, session: &str, ) -> Result<Vec<(String, i64, i64, i64)>, String>
Per-tool latency stats for a session: (name, count, avg_us, max_us).