-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from SeaQL/ss/bakery
Design and implement the Bakery Chain schema
- Loading branch information
Showing
18 changed files
with
1,336 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)] | ||
pub struct Entity; | ||
|
||
impl EntityName for Entity { | ||
fn table_name(&self) -> &str { | ||
"baker" | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] | ||
pub struct Model { | ||
pub id: i32, | ||
pub name: String, | ||
pub bakery_id: Option<i32>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] | ||
pub enum Column { | ||
Id, | ||
Name, | ||
BakeryId, | ||
} | ||
|
||
#[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 { | ||
Bakery, | ||
} | ||
|
||
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::BakeryId => ColumnType::Integer.def(), | ||
} | ||
} | ||
} | ||
|
||
impl RelationTrait for Relation { | ||
fn def(&self) -> RelationDef { | ||
match self { | ||
Self::Bakery => Entity::belongs_to(super::bakery::Entity) | ||
.from(Column::BakeryId) | ||
.to(super::bakery::Column::Id) | ||
.into(), | ||
} | ||
} | ||
} | ||
|
||
impl Related<super::bakery::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Bakery.def() | ||
} | ||
} | ||
|
||
impl Related<super::cake::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
super::cakes_bakers::Relation::Cake.def() | ||
} | ||
|
||
fn via() -> Option<RelationDef> { | ||
Some(super::cakes_bakers::Relation::Baker.def().rev()) | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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::Float.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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<mxfile host="Electron" modified="2021-06-30T11:15:47.471Z" agent="5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.6.13 Chrome/89.0.4389.128 Electron/12.0.7 Safari/537.36" etag="CL5AmeQl6dz-rdIIukNg" version="14.6.13" type="device"><diagram id="R2lEEEUBdFMjLlhIrx00" name="Page-1">7Zxtc5s4EIB/jT82w5sBf4yd5Nq75K6TdKbtp44Csq0zIB/Itd1ff6sgjI1EYoe3uxnNZDLWWgihZ1fsLmtG9ize/Zai9fKBhjgaWUa4G9k3I8uaOC7854J9LjB9w84li5SEQlYKnsgvLISGkG5IiLOTjozSiJH1qT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Ntqu6dLZWVkdyztTKt/UGmuVbt/Pu5avS7dt/AQ==</diagram></mxfile> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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 { | ||
"cake" | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] | ||
pub struct Model { | ||
pub id: i32, | ||
pub name: String, | ||
pub price: Decimal, | ||
pub bakery_id: Option<i32>, | ||
pub gluten_free: bool, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] | ||
pub enum Column { | ||
Id, | ||
Name, | ||
Price, | ||
BakeryId, | ||
GlutenFree, | ||
} | ||
|
||
#[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 { | ||
Bakery, | ||
Lineitem, | ||
} | ||
|
||
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::Price => ColumnType::Decimal(Some((19, 4))).def(), | ||
Self::BakeryId => ColumnType::Integer.def(), | ||
Self::GlutenFree => ColumnType::Boolean.def(), | ||
} | ||
} | ||
} | ||
|
||
impl RelationTrait for Relation { | ||
fn def(&self) -> RelationDef { | ||
match self { | ||
Self::Bakery => Entity::belongs_to(super::bakery::Entity) | ||
.from(Column::BakeryId) | ||
.to(super::bakery::Column::Id) | ||
.into(), | ||
Self::Lineitem => Entity::has_many(super::lineitem::Entity).into(), | ||
} | ||
} | ||
} | ||
|
||
impl Related<super::bakery::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Bakery.def() | ||
} | ||
} | ||
|
||
impl Related<super::baker::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
super::cakes_bakers::Relation::Baker.def() | ||
} | ||
|
||
fn via() -> Option<RelationDef> { | ||
Some(super::cakes_bakers::Relation::Cake.def().rev()) | ||
} | ||
} | ||
|
||
impl Related<super::lineitem::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Lineitem.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
Oops, something went wrong.