Record a history entry for a memory mutation.
(&self, history: &MemoryHistory)
| 211 | |
| 212 | /// Record a history entry for a memory mutation. |
| 213 | pub async fn insert_history(&self, history: &MemoryHistory) -> GraphBitResult<()> { |
| 214 | let memory_id = history.memory_id.to_string(); |
| 215 | let old_content = history.old_content.clone(); |
| 216 | let new_content = history.new_content.clone(); |
| 217 | let action = history.action.to_string(); |
| 218 | let timestamp = history.timestamp.to_rfc3339(); |
| 219 | let conn_arc = Arc::clone(&self.conn); |
| 220 | |
| 221 | tokio::task::spawn_blocking(move || -> GraphBitResult<()> { |
| 222 | let conn = conn_arc.blocking_lock(); |
| 223 | conn.execute( |
| 224 | "INSERT INTO memory_history (memory_id, old_content, new_content, action, timestamp) |
| 225 | VALUES (?1, ?2, ?3, ?4, ?5)", |
| 226 | rusqlite::params![memory_id, old_content, new_content, action, timestamp], |
| 227 | )?; |
| 228 | Ok(()) |
| 229 | }) |
| 230 | .await |
| 231 | .map_err(|e| GraphBitError::memory(format!("Join error: {e}")))? |
| 232 | } |
| 233 | |
| 234 | /// Get the full history for a specific memory. |
| 235 | pub async fn get_history(&self, memory_id: &MemoryId) -> GraphBitResult<Vec<MemoryHistory>> { |