use crate::error::LrefResult;
use crate::metadata::EntityTypeMeta;
use crate::provider::DbValue;
use std::collections::HashMap;
pub fn materialize_entities<T: IEntityType + IFromRow>(rows: &[Vec<String>]) -> LrefResult<Vec<T>> {
let mut entities = Vec::with_capacity(rows.len());
for row in rows {
let entity = T::from_row(row)?;
entities.push(entity);
}
Ok(entities)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EntityState {
Detached,
Added,
Unchanged,
Modified,
Deleted,
}
pub trait IEntityType: Send + Sync + 'static {
fn entity_meta() -> EntityTypeMeta
where
Self: Sized;
fn entity_meta_instance(&self) -> EntityTypeMeta
where
Self: Sized,
{
Self::entity_meta()
}
}
pub trait IFromRow: IEntityType + Sized {
fn from_row(values: &[String]) -> LrefResult<Self>;
}
pub trait IGetKeyValues: IEntityType {
fn key_values(&self) -> HashMap<String, DbValue>;
}
pub trait IEntitySnapshot: IEntityType {
fn snapshot(&self) -> HashMap<String, DbValue>;
}