Cargo fmt

This commit is contained in:
Sam Samai 2021-07-14 09:15:45 +10:00
parent 2e0f6df743
commit 406a9c6833

View File

@ -4,208 +4,208 @@ use sea_query::{ColumnDef, ForeignKey, ForeignKeyAction, Index, TableCreateState
pub use super::super::bakery_chain::*; pub use super::super::bakery_chain::*;
async fn create_table(db: &DbConn, stmt: &TableCreateStatement) -> Result<ExecResult, DbErr> { async fn create_table(db: &DbConn, stmt: &TableCreateStatement) -> Result<ExecResult, DbErr> {
let builder = db.get_schema_builder_backend(); let builder = db.get_schema_builder_backend();
db.execute(builder.build(stmt)).await db.execute(builder.build(stmt)).await
} }
pub async fn create_bakery_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_bakery_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(bakery::Entity) .table(bakery::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(bakery::Column::Id) ColumnDef::new(bakery::Column::Id)
.integer() .integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(bakery::Column::Name).string()) .col(ColumnDef::new(bakery::Column::Name).string())
.col(ColumnDef::new(bakery::Column::ProfitMargin).double()) .col(ColumnDef::new(bakery::Column::ProfitMargin).double())
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }
pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(baker::Entity) .table(baker::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(baker::Column::Id) ColumnDef::new(baker::Column::Id)
.integer() .integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(baker::Column::Name).string()) .col(ColumnDef::new(baker::Column::Name).string())
.col(ColumnDef::new(baker::Column::BakeryId).integer()) .col(ColumnDef::new(baker::Column::BakeryId).integer())
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("FK_baker_bakery") .name("FK_baker_bakery")
.from(baker::Entity, baker::Column::BakeryId) .from(baker::Entity, baker::Column::BakeryId)
.to(bakery::Entity, bakery::Column::Id) .to(bakery::Entity, bakery::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }
pub async fn create_customer_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_customer_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(customer::Entity) .table(customer::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(customer::Column::Id) ColumnDef::new(customer::Column::Id)
.integer() .integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(customer::Column::Name).string()) .col(ColumnDef::new(customer::Column::Name).string())
.col(ColumnDef::new(customer::Column::Notes).text()) .col(ColumnDef::new(customer::Column::Notes).text())
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }
pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(order::Entity) .table(order::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(order::Column::Id) ColumnDef::new(order::Column::Id)
.integer() .integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(order::Column::Total).float()) .col(ColumnDef::new(order::Column::Total).float())
.col(ColumnDef::new(order::Column::BakeryId).integer().not_null()) .col(ColumnDef::new(order::Column::BakeryId).integer().not_null())
.col( .col(
ColumnDef::new(order::Column::CustomerId) ColumnDef::new(order::Column::CustomerId)
.integer() .integer()
.not_null(), .not_null(),
) )
.col( .col(
ColumnDef::new(order::Column::PlacedAt) ColumnDef::new(order::Column::PlacedAt)
.date_time() .date_time()
.not_null(), .not_null(),
) )
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("FK_order_bakery") .name("FK_order_bakery")
.from(order::Entity, order::Column::BakeryId) .from(order::Entity, order::Column::BakeryId)
.to(bakery::Entity, bakery::Column::Id) .to(bakery::Entity, bakery::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("FK_order_customer") .name("FK_order_customer")
.from(order::Entity, order::Column::CustomerId) .from(order::Entity, order::Column::CustomerId)
.to(customer::Entity, customer::Column::Id) .to(customer::Entity, customer::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }
pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(lineitem::Entity) .table(lineitem::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(lineitem::Column::Id) ColumnDef::new(lineitem::Column::Id)
.integer() .integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(lineitem::Column::Price).decimal()) .col(ColumnDef::new(lineitem::Column::Price).decimal())
.col(ColumnDef::new(lineitem::Column::Quantity).integer()) .col(ColumnDef::new(lineitem::Column::Quantity).integer())
.col( .col(
ColumnDef::new(lineitem::Column::OrderId) ColumnDef::new(lineitem::Column::OrderId)
.integer() .integer()
.not_null(), .not_null(),
) )
.col( .col(
ColumnDef::new(lineitem::Column::CakeId) ColumnDef::new(lineitem::Column::CakeId)
.integer() .integer()
.not_null(), .not_null(),
) )
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("FK_lineitem_order") .name("FK_lineitem_order")
.from(lineitem::Entity, lineitem::Column::OrderId) .from(lineitem::Entity, lineitem::Column::OrderId)
.to(order::Entity, order::Column::Id) .to(order::Entity, order::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("FK_lineitem_cake") .name("FK_lineitem_cake")
.from(lineitem::Entity, lineitem::Column::CakeId) .from(lineitem::Entity, lineitem::Column::CakeId)
.to(cake::Entity, cake::Column::Id) .to(cake::Entity, cake::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }
pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(cakes_bakers::Entity) .table(cakes_bakers::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(cakes_bakers::Column::CakeId) ColumnDef::new(cakes_bakers::Column::CakeId)
.integer() .integer()
.not_null(), .not_null(),
) )
.col( .col(
ColumnDef::new(cakes_bakers::Column::BakerId) ColumnDef::new(cakes_bakers::Column::BakerId)
.integer() .integer()
.not_null(), .not_null(),
) )
.primary_key( .primary_key(
Index::create() Index::create()
.col(cakes_bakers::Column::CakeId) .col(cakes_bakers::Column::CakeId)
.col(cakes_bakers::Column::BakerId), .col(cakes_bakers::Column::BakerId),
) )
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }
pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> { pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
let stmt = sea_query::Table::create() let stmt = sea_query::Table::create()
.table(cake::Entity) .table(cake::Entity)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(cake::Column::Id) ColumnDef::new(cake::Column::Id)
.integer() .integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col(ColumnDef::new(cake::Column::Name).string()) .col(ColumnDef::new(cake::Column::Name).string())
.col(ColumnDef::new(cake::Column::Price).float()) .col(ColumnDef::new(cake::Column::Price).float())
.col(ColumnDef::new(cake::Column::BakeryId).integer().not_null()) .col(ColumnDef::new(cake::Column::BakeryId).integer().not_null())
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("FK_cake_bakery") .name("FK_cake_bakery")
.from(cake::Entity, cake::Column::BakeryId) .from(cake::Entity, cake::Column::BakeryId)
.to(bakery::Entity, bakery::Column::Id) .to(bakery::Entity, bakery::Column::Id)
.on_delete(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade), .on_update(ForeignKeyAction::Cascade),
) )
.col(ColumnDef::new(cake::Column::GlutenFree).boolean()) .col(ColumnDef::new(cake::Column::GlutenFree).boolean())
.to_owned(); .to_owned();
create_table(db, &stmt).await create_table(db, &stmt).await
} }