90 lines
2.0 KiB
Rust
90 lines
2.0 KiB
Rust
use rust_decimal::prelude::*;
|
|
use sea_orm::entity::prelude::*;
|
|
|
|
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
|
pub struct Entity;
|
|
|
|
impl EntityName for Entity {
|
|
fn table_name(&self) -> &str {
|
|
"lineitem"
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
|
pub struct Model {
|
|
pub id: i32,
|
|
pub price: Decimal,
|
|
pub quantity: i32,
|
|
pub order_id: Option<i32>,
|
|
pub cake_id: Option<i32>,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
pub enum Column {
|
|
Id,
|
|
Price,
|
|
Quantity,
|
|
OrderId,
|
|
CakeId,
|
|
}
|
|
|
|
#[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 {
|
|
Order,
|
|
Cake,
|
|
}
|
|
|
|
impl ColumnTrait for Column {
|
|
type EntityName = Entity;
|
|
|
|
fn def(&self) -> ColumnDef {
|
|
match self {
|
|
Self::Id => ColumnType::Integer.def(),
|
|
Self::Price => ColumnType::Money(Some((19, 4))).def(),
|
|
Self::Quantity => ColumnType::Integer.def(),
|
|
Self::OrderId => ColumnType::Integer.def(),
|
|
Self::CakeId => ColumnType::Integer.def(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl RelationTrait for Relation {
|
|
fn def(&self) -> RelationDef {
|
|
match self {
|
|
Self::Order => Entity::belongs_to(super::order::Entity)
|
|
.from(Column::OrderId)
|
|
.to(super::order::Column::Id)
|
|
.into(),
|
|
Self::Cake => Entity::belongs_to(super::cake::Entity)
|
|
.from(Column::CakeId)
|
|
.to(super::cake::Column::Id)
|
|
.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
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 {}
|