use crate::model::{field::FieldModel, index::IndexModel};
#[derive(Debug)]
pub struct EntityModel {
pub(crate) path: &'static str,
pub(crate) entity_name: &'static str,
pub(crate) primary_key: &'static FieldModel,
pub(crate) primary_key_slot: usize,
pub(crate) fields: &'static [FieldModel],
pub(crate) indexes: &'static [&'static IndexModel],
}
impl EntityModel {
#[must_use]
#[doc(hidden)]
pub const fn generated(
path: &'static str,
entity_name: &'static str,
primary_key: &'static FieldModel,
primary_key_slot: usize,
fields: &'static [FieldModel],
indexes: &'static [&'static IndexModel],
) -> Self {
Self {
path,
entity_name,
primary_key,
primary_key_slot,
fields,
indexes,
}
}
#[must_use]
pub const fn path(&self) -> &'static str {
self.path
}
#[must_use]
pub const fn name(&self) -> &'static str {
self.entity_name
}
#[must_use]
pub const fn primary_key(&self) -> &'static FieldModel {
self.primary_key
}
#[must_use]
pub const fn primary_key_slot(&self) -> usize {
self.primary_key_slot
}
#[must_use]
pub const fn fields(&self) -> &'static [FieldModel] {
self.fields
}
#[must_use]
pub const fn indexes(&self) -> &'static [&'static IndexModel] {
self.indexes
}
}
#[must_use]
pub(crate) fn resolve_field_slot(model: &EntityModel, field_name: &str) -> Option<usize> {
model
.fields
.iter()
.position(|field| field.name == field_name)
}