diff --git a/01.workspace/heave/src/fun/sqlite_load_by_class.rs b/01.workspace/heave/src/fun/sqlite_load_by_class.rs index 6426565..5a9d4ff 100644 --- a/01.workspace/heave/src/fun/sqlite_load_by_class.rs +++ b/01.workspace/heave/src/fun/sqlite_load_by_class.rs @@ -16,6 +16,7 @@ pub fn run(path: &path::Path, entity_class: &str) -> Vec { for entity in result { let mut entity = entity.unwrap(); sqlite::load::attributes(&connection, &mut entity); + entity.state = EntityState::Loaded; entities.push(entity); } entities diff --git a/01.workspace/heave/src/fun/sqlite_load_by_id.rs b/01.workspace/heave/src/fun/sqlite_load_by_id.rs index 2a908f2..17fb1a1 100644 --- a/01.workspace/heave/src/fun/sqlite_load_by_id.rs +++ b/01.workspace/heave/src/fun/sqlite_load_by_id.rs @@ -14,6 +14,7 @@ pub fn run(path: &path::Path, entity_id: &str) -> Option { let mut entity = result.unwrap(); if let Some(ref mut entity) = entity { sqlite::load::attributes(&connection, entity); + entity.state = EntityState::Loaded; } entity } diff --git a/01.workspace/heave/src/fun/sqlite_persist_catalog.rs b/01.workspace/heave/src/fun/sqlite_persist_catalog.rs index ca1d562..6d2754b 100644 --- a/01.workspace/heave/src/fun/sqlite_persist_catalog.rs +++ b/01.workspace/heave/src/fun/sqlite_persist_catalog.rs @@ -37,6 +37,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); + println!("Writing: {:?}", entity_values); let _ = transaction.execute(DELETE_ENTITY_STATEMENT, entity_id); let _ = transaction.execute(INSERT_ENTITY_STATEMENT, entity_values); for (_key, attribute) in entity.attributes.iter() { @@ -47,7 +48,11 @@ fn write_entity(entity: &Entity, transaction: &rusqlite::Transaction) { pub fn run(path: &path::Path, catalog: &Catalog) { let mut connection = Connection::open(path).unwrap(); let transaction = connection.transaction().unwrap(); - for (_key, entity) in catalog.items.iter() { + for (_key, entity) in catalog + .items + .iter() + .filter(|item| item.1.state == EntityState::New) + { write_entity(entity, &transaction); } let _ = transaction.commit(); diff --git a/01.workspace/heave/src/lib.rs b/01.workspace/heave/src/lib.rs index 2389bdc..35a3975 100644 --- a/01.workspace/heave/src/lib.rs +++ b/01.workspace/heave/src/lib.rs @@ -10,6 +10,7 @@ mod tst; pub use crate::str::attribute::O as Attribute; pub use crate::str::catalog::O as Catalog; pub use crate::str::entity::O as Entity; +pub use crate::str::entity_state::E as EntityState; pub use crate::str::value::E as Value; pub use crate::trt::eav::T as EAV; diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index ebf18c1..9005c4e 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -18,12 +18,14 @@ impl O { sqlite::init::db(path); } pub fn insert(&mut self, object: impl EAV) { - let entity = object.into(); + let mut entity = object.into(); + entity.state = EntityState::New; self.items.insert(entity.id.clone(), entity); } pub fn insert_many(&mut self, objects: Vec) { for object in objects { - let entity = object.into(); + let mut entity = object.into(); + entity.state = EntityState::New; self.items.insert(entity.id.clone(), entity); } } diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index a591282..30e0ebf 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -3,6 +3,7 @@ use crate::*; #[derive(Debug, Default, PartialEq, Clone)] pub struct O { pub id: String, + pub state: EntityState, pub class: String, pub attributes: std::collections::HashMap, } diff --git a/01.workspace/heave/src/str/entity_state.rs b/01.workspace/heave/src/str/entity_state.rs new file mode 100644 index 0000000..e3bbeb5 --- /dev/null +++ b/01.workspace/heave/src/str/entity_state.rs @@ -0,0 +1,6 @@ +#[derive(Debug, Default, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Hash)] +pub enum E { + #[default] + New, + Loaded, +} diff --git a/01.workspace/heave/src/str/mod.rs b/01.workspace/heave/src/str/mod.rs index d11628e..1a1a6e5 100644 --- a/01.workspace/heave/src/str/mod.rs +++ b/01.workspace/heave/src/str/mod.rs @@ -1,4 +1,5 @@ pub mod attribute; pub mod catalog; pub mod entity; +pub mod entity_state; pub mod value;