feat: Support incremental mode:

- Support incremental mode in heromodels
- Updated the example to refelct the changes
- Updated the tests to reflect the changes
This commit is contained in:
Mahmoud Emad
2025-05-17 11:12:09 +03:00
parent bd4770b99b
commit bde5db0e52
16 changed files with 1074 additions and 136 deletions

View File

@@ -59,13 +59,14 @@ pub trait Model:
}
/// Get the unique ID for this model
/// Returns 0 if the ID is None
fn get_id(&self) -> u32;
/// Get a mutable reference to the base_data field
fn base_data_mut(&mut self) -> &mut BaseModelData;
/// Set the ID for this model
fn id(mut self, id: u32) -> Self
fn id(mut self, id: Option<u32>) -> Self
where
Self: Sized,
{
@@ -98,7 +99,7 @@ pub trait Index {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BaseModelData {
/// Unique incremental ID per circle
pub id: u32,
pub id: Option<u32>,
/// Unix epoch timestamp for creation time
pub created_at: i64,
@@ -112,7 +113,7 @@ pub struct BaseModelData {
impl BaseModelData {
/// Create a new BaseModelData instance
pub fn new(id: u32) -> Self {
pub fn new(id: Option<u32>) -> Self {
let now = chrono::Utc::now().timestamp();
Self {
id,
@@ -123,7 +124,7 @@ impl BaseModelData {
}
/// Create a new BaseModelDataBuilder
pub fn builder(id: u32) -> BaseModelDataBuilder {
pub fn builder(id: Option<u32>) -> BaseModelDataBuilder {
BaseModelDataBuilder::new(id)
}
@@ -147,7 +148,7 @@ impl BaseModelData {
/// Builder for BaseModelData
pub struct BaseModelDataBuilder {
id: u32,
id: Option<u32>,
created_at: Option<i64>,
modified_at: Option<i64>,
comments: Vec<u32>,
@@ -155,7 +156,7 @@ pub struct BaseModelDataBuilder {
impl BaseModelDataBuilder {
/// Create a new BaseModelDataBuilder
pub fn new(id: u32) -> Self {
pub fn new(id: Option<u32>) -> Self {
Self {
id,
created_at: None,