use crate::{ColumnSpec, ForeignKeySpec, IndexSpec, Result, Row};
use sea_query::Value;
pub trait Entity: Sized {
fn table() -> &'static str;
fn columns() -> &'static [ColumnSpec];
fn primary_key() -> &'static str;
fn indexes() -> &'static [IndexSpec] {
&[]
}
fn foreign_keys() -> &'static [ForeignKeySpec] {
&[]
}
fn shard_columns() -> &'static [&'static str] {
&[]
}
fn from_row(row: &dyn Row) -> Result<Self>;
fn insert_values(&self) -> Vec<(&'static str, Value)>;
fn update_values(&self) -> Vec<(&'static str, Value)>;
fn pk_value(&self) -> Value;
fn value_of(&self, column: &str) -> Option<Value> {
if column == Self::primary_key() {
return Some(self.pk_value());
}
self.update_values().into_iter().find(|(name, _)| *name == column).map(|(_, value)| value)
}
}