use sqlx::SqlitePool;
use crate::error::ClawResult;
pub struct IndexManager<'a> {
pool: &'a SqlitePool,
}
impl<'a> IndexManager<'a> {
pub fn new(pool: &'a SqlitePool) -> Self {
IndexManager { pool }
}
pub async fn ensure_active_memory_agent_index(&self) -> ClawResult<()> {
sqlx::query(
"CREATE INDEX IF NOT EXISTS idx_active_memory_agent_id \
ON active_memory (agent_id)",
)
.execute(self.pool)
.await?;
Ok(())
}
pub async fn ensure_session_index(&self) -> ClawResult<()> {
sqlx::query(
"CREATE INDEX IF NOT EXISTS idx_session_state_session_id \
ON session_state (session_id)",
)
.execute(self.pool)
.await?;
Ok(())
}
pub async fn ensure_tool_output_index(&self) -> ClawResult<()> {
sqlx::query(
"CREATE INDEX IF NOT EXISTS idx_tool_output_tool_name_created_at \
ON tool_output (tool_name, created_at)",
)
.execute(self.pool)
.await?;
Ok(())
}
}
impl<'a> std::fmt::Debug for IndexManager<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IndexManager").finish_non_exhaustive()
}
}