Get a single memory by ID.
(&self, memory_id: &MemoryId)
| 99 | |
| 100 | /// Get a single memory by ID. |
| 101 | pub async fn get_memory(&self, memory_id: &MemoryId) -> GraphBitResult<Option<Memory>> { |
| 102 | let id = memory_id.to_string(); |
| 103 | let conn_arc = Arc::clone(&self.conn); |
| 104 | |
| 105 | tokio::task::spawn_blocking(move || -> GraphBitResult<Option<Memory>> { |
| 106 | let conn = conn_arc.blocking_lock(); |
| 107 | let mut stmt = |
| 108 | conn.prepare("SELECT id, content, user_id, agent_id, run_id, hash, metadata, created_at, updated_at FROM memories WHERE id = ?1")?; |
| 109 | let mut rows = stmt.query(rusqlite::params![id])?; |
| 110 | if let Some(row) = rows.next()? { |
| 111 | Ok(Some(row_to_memory(row)?)) |
| 112 | } else { |
| 113 | Ok(None) |
| 114 | } |
| 115 | }) |
| 116 | .await |
| 117 | .map_err(|e| GraphBitError::memory(format!("Join error: {e}")))? |
| 118 | } |
| 119 | |
| 120 | /// Get all memories matching the given scope. |
| 121 | pub async fn get_all_memories(&self, scope: &MemoryScope) -> GraphBitResult<Vec<Memory>> { |