85 lines
1.7 KiB
Rust
85 lines
1.7 KiB
Rust
use sea_orm::entity::prelude::*;
|
|
|
|
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
|
pub struct Entity;
|
|
|
|
impl EntityName for Entity {
|
|
fn table_name(&self) -> &str {
|
|
"bakery"
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
|
pub struct Model {
|
|
pub id: i32,
|
|
pub name: String,
|
|
pub profit_margin: f64,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
pub enum Column {
|
|
Id,
|
|
Name,
|
|
ProfitMargin,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
|
pub enum PrimaryKey {
|
|
Id,
|
|
}
|
|
|
|
impl PrimaryKeyTrait for PrimaryKey {
|
|
fn auto_increment() -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
pub enum Relation {
|
|
Baker,
|
|
Order,
|
|
Cake,
|
|
}
|
|
|
|
impl ColumnTrait for Column {
|
|
type EntityName = Entity;
|
|
|
|
fn def(&self) -> ColumnDef {
|
|
match self {
|
|
Self::Id => ColumnType::Integer.def(),
|
|
Self::Name => ColumnType::String(None).def(),
|
|
Self::ProfitMargin => ColumnType::Double.def(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl RelationTrait for Relation {
|
|
fn def(&self) -> RelationDef {
|
|
match self {
|
|
Self::Baker => Entity::has_many(super::baker::Entity).into(),
|
|
Self::Order => Entity::has_many(super::order::Entity).into(),
|
|
Self::Cake => Entity::has_many(super::cake::Entity).into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Related<super::baker::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Baker.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::order::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Order.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::cake::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Cake.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|