feat: make ref_date optional

This commit is contained in:
2025-10-01 11:44:25 +02:00
parent 36bb9e3845
commit 05085a0f7b
3 changed files with 11 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ pub fn run(path: &path::Path) {
CREATE TABLE IF NOT EXISTS entity (
id TEXT PRIMARY KEY,
class TEXT NOT NULL,
ref_date INTEGER NOT NULL
ref_date INTEGER
);
CREATE TABLE IF NOT EXISTS attribute (
id TEXT,

View File

@@ -3,11 +3,14 @@ use crate::*;
pub fn run(row: &rusqlite::Row) -> rusqlite::Result<Entity> {
let id: String = row.get(0)?;
let class: String = row.get(1)?;
let ref_date: u64 = row.get(2)?;
Ok(Entity::default()
.with_id(&id)
.with_class(&class)
.with_ref_date(ref_date))
let ref_date: Option<u64> = row.get(2)?;
let entity = Entity {
id,
class,
ref_date,
..Entity::default()
};
Ok(entity)
}
// #[cfg(test)]

View File

@@ -4,7 +4,7 @@ use crate::*;
pub struct O {
pub id: String,
pub state: EntityState,
pub ref_date: u64,
pub ref_date: Option<u64>,
pub class: String,
pub attributes: std::collections::HashMap<String, Attribute>,
}
@@ -28,7 +28,7 @@ impl O {
self
}
pub fn with_ref_date(mut self, ref_date: u64) -> Self {
self.ref_date = ref_date;
self.ref_date = Some(ref_date);
self
}
pub fn with_attribute(mut self, id: &str, value: impl Into<Value>) -> Self {