diff --git a/01.workspace/heave/src/fun/sqlite_init_db.rs b/01.workspace/heave/src/fun/sqlite_init_db.rs index 224e5e3..9deb235 100644 --- a/01.workspace/heave/src/fun/sqlite_init_db.rs +++ b/01.workspace/heave/src/fun/sqlite_init_db.rs @@ -5,7 +5,8 @@ pub fn run(path: &path::Path) { let init_statement = r#" CREATE TABLE IF NOT EXISTS entity ( id TEXT PRIMARY KEY, - class TEXT NOT NULL + class TEXT NOT NULL, + ref_date INTEGER NOT NULL ); CREATE TABLE IF NOT EXISTS attribute ( id TEXT, diff --git a/01.workspace/heave/src/fun/sqlite_map_row_to_entity.rs b/01.workspace/heave/src/fun/sqlite_map_row_to_entity.rs index a0512e4..53daac1 100644 --- a/01.workspace/heave/src/fun/sqlite_map_row_to_entity.rs +++ b/01.workspace/heave/src/fun/sqlite_map_row_to_entity.rs @@ -3,7 +3,11 @@ use crate::*; pub fn run(row: &rusqlite::Row) -> rusqlite::Result { let id: String = row.get(0)?; let class: String = row.get(1)?; - Ok(Entity::default().with_id(&id).with_class(&class)) + let ref_date: u64 = row.get(2)?; + Ok(Entity::default() + .with_id(&id) + .with_class(&class) + .with_ref_date(ref_date)) } // #[cfg(test)] diff --git a/01.workspace/heave/src/fun/sqlite_persist_catalog.rs b/01.workspace/heave/src/fun/sqlite_persist_catalog.rs index 7ead46a..b38b0bc 100644 --- a/01.workspace/heave/src/fun/sqlite_persist_catalog.rs +++ b/01.workspace/heave/src/fun/sqlite_persist_catalog.rs @@ -17,8 +17,8 @@ const DELETE_ENTITY_STATEMENT: &str = r#" "#; const INSERT_ENTITY_STATEMENT: &str = r#" - INSERT INTO entity (id, class) - VALUES (?1, ?2); + INSERT INTO entity (id, class, ref_date) + VALUES (?1, ?2, ?3); "#; const INSERT_ATTRIBUTE_STATEMENT_TEMPLATE: &str = r#" @@ -36,7 +36,7 @@ fn write_attribute(attribute: &Attribute, entity: &Entity, transaction: &rusqlit fn write_entity(entity: &Entity, transaction: &rusqlite::Transaction) { let entity_id = [&entity.id]; - let entity_values = (&entity.id, &entity.class); + let entity_values = (&entity.id, &entity.class, entity.ref_date); let _ = transaction.execute(DELETE_ENTITY_STATEMENT, entity_id); let _ = transaction.execute(INSERT_ENTITY_STATEMENT, entity_values); for (_key, attribute) in entity.attributes.iter() { diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index e080a3c..61cfa9f 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -4,6 +4,7 @@ use crate::*; pub struct O { pub id: String, pub state: EntityState, + pub ref_date: u64, pub class: String, pub attributes: std::collections::HashMap, } @@ -26,6 +27,10 @@ impl O { self.class = class.to_string(); self } + pub fn with_ref_date(mut self, ref_date: u64) -> Self { + self.ref_date = ref_date; + self + } pub fn with_attribute(mut self, id: &str, value: impl Into) -> Self { let attribute = Attribute::new(id, value); self.attributes.insert(attribute.id.clone(), attribute);