engram_storage/
consolidation_log.rs1use rusqlite::params;
2
3use crate::database::Database;
4use crate::error::StorageError;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct ConsolidationLogEntry {
8 pub id: String,
9 pub action: String,
10 pub memory_ids_json: String,
11 pub reason: Option<String>,
12 pub performed_at: String,
13 pub performed_by: String,
14}
15
16impl Database {
17 pub fn list_consolidation_log(
18 &self,
19 limit: usize,
20 ) -> Result<Vec<ConsolidationLogEntry>, StorageError> {
21 let mut statement = self.connection().prepare(
22 "SELECT id, action, memory_ids, reason, performed_at, performed_by
23 FROM consolidation_log
24 ORDER BY performed_at DESC, id DESC
25 LIMIT ?1",
26 )?;
27 let rows = statement.query_map(params![limit as i64], |row| {
28 Ok(ConsolidationLogEntry {
29 id: row.get(0)?,
30 action: row.get(1)?,
31 memory_ids_json: row.get(2)?,
32 reason: row.get(3)?,
33 performed_at: row.get(4)?,
34 performed_by: row.get(5)?,
35 })
36 })?;
37 let mut entries = Vec::new();
38 for row in rows {
39 entries.push(row?);
40 }
41 Ok(entries)
42 }
43}