use crate::error::EFResult;
use crate::metadata::EntityTypeMeta;
use crate::provider::DbValue;
use std::collections::HashMap;
pub fn materialize_entities<T: IEntityType + IFromRow>(rows: &[Vec<DbValue>]) -> EFResult<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: &[DbValue]) -> EFResult<Self>;
}
pub trait IGetKeyValues: IEntityType {
fn key_values(&self) -> HashMap<String, DbValue>;
}
pub trait IEntitySnapshot: IEntityType {
fn snapshot(&self) -> HashMap<String, DbValue>;
}
pub trait ILazyInit: IEntityType {
fn attach_lazy_contexts(
&mut self,
provider: std::sync::Arc<dyn crate::provider::IDatabaseProvider>,
filter_map: Option<
std::sync::Arc<std::collections::HashMap<String, crate::query::CompiledFilter>>,
>,
depth: usize,
);
}
#[async_trait::async_trait]
pub trait INavigationSetter: IEntityType {
fn apply_has_many(&mut self, field: &str, rows: &[Vec<DbValue>]) -> EFResult<()> {
let _ = (field, rows);
Ok(())
}
fn apply_reference(&mut self, field: &str, row: &[DbValue]) -> EFResult<()> {
let _ = (field, row);
Ok(())
}
async fn load_nested_includes(
&mut self,
parent_navigation: &str,
nested: &[crate::query::IncludePath],
provider: &dyn crate::provider::IDatabaseProvider,
filter_map: Option<&std::collections::HashMap<String, crate::query::CompiledFilter>>,
) -> EFResult<()> {
let _ = (parent_navigation, nested, provider, filter_map);
Ok(())
}
}