refactor: remove ToEAV trait in favor of Into<Entity>

This commit is contained in:
2025-09-30 07:19:09 +02:00
parent 70c3b9108e
commit 502fc8b7d0
9 changed files with 28 additions and 41 deletions

View File

@@ -11,10 +11,10 @@ pub mod string_from_value;
// pub mod string_to_value;
pub mod u64_from_value;
// pub mod u64_to_value;
pub mod value_from_bool;
pub mod value_from_entity;
pub mod value_from_f64;
pub mod value_from_i64;
pub mod value_from_str;
pub mod value_from_string;
pub mod value_from_u64;
pub mod value_from_f64;
pub mod value_from_bool;
pub mod value_from_entity;
pub mod value_from_i64;

View File

@@ -12,7 +12,6 @@ pub use crate::str::catalog::O as Catalog;
pub use crate::str::entity::O as Entity;
pub use crate::str::value::E as Value;
pub use crate::trt::eav::T as EAV;
pub use crate::trt::to_eav::T as ToEAV;
mod sqlite {
pub mod init {

View File

@@ -19,12 +19,12 @@ impl O {
sqlite::init::db(path);
}
pub fn insert(&mut self, object: impl EAV) {
let entity = object.to_eav();
let entity = object.into();
self.items.insert(entity.id.clone(), entity);
}
pub fn insert_many(&mut self, objects: Vec<impl EAV>) {
for object in objects {
let entity = object.to_eav();
let entity = object.into();
self.items.insert(entity.id.clone(), entity);
}
}

View File

@@ -9,12 +9,6 @@ pub struct O {
impl EAV for Entity {}
impl ToEAV for Entity {
fn to_eav(self) -> Entity {
self
}
}
impl O {
pub fn new(class: &str) -> Self {
Self {

View File

@@ -3,7 +3,7 @@ use crate::*;
/// TODO: INSERT DOCUMENTATION HERE
pub trait T where
Self: From<Entity>,
Self: ToEAV,
Self: Into<Entity>,
{
}

View File

@@ -1,2 +1 @@
pub mod eav;
pub mod to_eav;

View File

@@ -1,5 +0,0 @@
use crate::*;
pub trait T {
fn to_eav(self) -> Entity;
}

View File

@@ -8,13 +8,13 @@ mod tests {
pub price: u64,
}
impl EAV for Product {}
impl ToEAV for Product {
fn to_eav(self) -> Entity {
impl From<Product> for Entity {
fn from(value: Product) -> Entity {
Entity::default()
.with_class("product")
.with_id(&self.id)
.with_attribute("name", self.name)
.with_attribute("price", self.price)
.with_id(&value.id)
.with_attribute("name", value.name)
.with_attribute("price", value.price)
}
}
impl From<Entity> for Product {
@@ -118,7 +118,7 @@ mod tests {
price: 200000u64,
};
let expected_product = product.clone();
let entity = product.to_eav();
let entity: Entity = product.into();
let converted_product = Product::from(entity);
assert_eq!(expected_product, converted_product);
}

View File

@@ -12,13 +12,13 @@ mod tests {
pub category_id: String,
}
impl EAV for OperationToCategory {}
impl ToEAV for OperationToCategory {
fn to_eav(self) -> Entity {
impl From<OperationToCategory> for Entity {
fn from(value: OperationToCategory) -> Entity {
Entity::default()
.with_class("operation_has_category")
.with_id(&self.id)
.with_attribute("operation_id", self.operation_id)
.with_attribute("category_id", self.category_id)
.with_id(&value.id)
.with_attribute("operation_id", value.operation_id)
.with_attribute("category_id", value.category_id)
}
}
impl From<Entity> for OperationToCategory {
@@ -38,12 +38,12 @@ mod tests {
pub label: String,
}
impl EAV for Category {}
impl ToEAV for Category {
fn to_eav(self) -> Entity {
impl From<Category> for Entity {
fn from(value: Category) -> Entity {
Entity::default()
.with_class("category")
.with_id(&self.id)
.with_attribute("label", self.label)
.with_id(&value.id)
.with_attribute("label", value.label)
}
}
impl From<Entity> for Category {
@@ -64,14 +64,14 @@ mod tests {
pub description: String,
}
impl EAV for Operation {}
impl ToEAV for Operation {
fn to_eav(self) -> Entity {
impl From<Operation> for Entity {
fn from(value: Operation) -> Entity {
Entity::default()
.with_class("operation")
.with_id(&self.id)
.with_attribute("date", self.date)
.with_attribute("amount", self.amount)
.with_attribute("description", self.description)
.with_id(&value.id)
.with_attribute("date", value.date)
.with_attribute("amount", value.amount)
.with_attribute("description", value.description)
}
}
impl From<Entity> for Operation {