Update content and metadata of an existing memory.
(
&self,
memory_id: &MemoryId,
content: &str,
hash: &str,
)
| 147 | |
| 148 | /// Update content and metadata of an existing memory. |
| 149 | pub async fn update_memory( |
| 150 | &self, |
| 151 | memory_id: &MemoryId, |
| 152 | content: &str, |
| 153 | hash: &str, |
| 154 | ) -> GraphBitResult<()> { |
| 155 | let id = memory_id.to_string(); |
| 156 | let content = content.to_string(); |
| 157 | let hash = hash.to_string(); |
| 158 | let updated_at = Utc::now().to_rfc3339(); |
| 159 | let conn_arc = Arc::clone(&self.conn); |
| 160 | |
| 161 | tokio::task::spawn_blocking(move || -> GraphBitResult<()> { |
| 162 | let conn = conn_arc.blocking_lock(); |
| 163 | let changed = conn.execute( |
| 164 | "UPDATE memories SET content = ?1, hash = ?2, updated_at = ?3 WHERE id = ?4", |
| 165 | rusqlite::params![content, hash, updated_at, id], |
| 166 | )?; |
| 167 | if changed == 0 { |
| 168 | return Err(GraphBitError::memory(format!( |
| 169 | "Memory not found: {id}" |
| 170 | ))); |
| 171 | } |
| 172 | Ok(()) |
| 173 | }) |
| 174 | .await |
| 175 | .map_err(|e| GraphBitError::memory(format!("Join error: {e}")))? |
| 176 | } |
| 177 | |
| 178 | /// Delete a single memory by ID. |
| 179 | pub async fn delete_memory(&self, memory_id: &MemoryId) -> GraphBitResult<()> { |