* Add DeriveRelatedEntity macro * Add generation for related enum and seaography * Add seaography cli param * update codegen tests * Fix DeriveRelatedEntity macro doc and includes * Fix all RelatedEntity variants for RelationBuilder * Add tests for code * Cargo format * Fix clippy code * Fix format * Fix unit tests * Fix unit tests * Provide default for seaography::RelationBuilder * Update changelog * Update tests * Modify code to match feedback * Bring old Related Impl trait generation * Modify DeriveRelatedEntity to gen impl seaography::RelationBuilder * Generate RelatedEntity enum when seaography flag is enabled * Update documentation * Update Changelog * Fix format errors * Fix code generation * relations with suffix are definition based * Rev => Reverse easier to read * snake_case to cameCase for name generation * Fix unit tests * Update lib.rs * derive `seaography::RelationBuilder` only when `seaography` feature is enabled * Try constructing async-graphql root for "related entity" and "entity" without relation * Update demo * CHANGELOG * Update Cargo.toml Co-authored-by: Chris Tsang <chris.2y3@outlook.com> * Revert "Update Cargo.toml" This reverts commit 6b1669836a4fb5040bfb08999f0cf640c74dc64d. --------- Co-authored-by: Billy Chan <ccw.billy.123@gmail.com> Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
95 lines
2.1 KiB
Rust
95 lines
2.1 KiB
Rust
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0
|
|
|
|
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, Eq)]
|
|
pub struct Model {
|
|
pub id: i32,
|
|
pub name: Option<String> ,
|
|
pub base_id: Option<i32> ,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
pub enum Column {
|
|
Id,
|
|
Name,
|
|
BaseId,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
|
pub enum PrimaryKey {
|
|
Id,
|
|
}
|
|
|
|
impl PrimaryKeyTrait for PrimaryKey {
|
|
type ValueType = i32;
|
|
|
|
fn auto_increment() -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
pub enum Relation {
|
|
Fruit,
|
|
SelfRef ,
|
|
}
|
|
|
|
impl ColumnTrait for Column {
|
|
type EntityName = Entity;
|
|
fn def(&self) -> ColumnDef {
|
|
match self {
|
|
Self::Id => ColumnType::Integer.def(),
|
|
Self::Name => ColumnType::Text.def().null(),
|
|
Self::BaseId => ColumnType::Integer.def().null(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl RelationTrait for Relation {
|
|
fn def(&self) -> RelationDef {
|
|
match self {
|
|
Self::Fruit => Entity::has_many(super::fruit::Entity).into(),
|
|
Self::SelfRef => Entity::has_one(Entity).into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Related<super::fruit::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Fruit.def()
|
|
}
|
|
}
|
|
|
|
impl Related<super::filling::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
super::cake_filling::Relation::Filling.def()
|
|
}
|
|
fn via() -> Option<RelationDef> {
|
|
Some(super::cake_filling::Relation::Cake.def().rev())
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)]
|
|
pub enum RelatedEntity {
|
|
#[sea_orm(entity = "super::fruit::Entity")]
|
|
Fruit,
|
|
#[sea_orm(entity = "Entity", def = "Relation::SelfRef.def()")]
|
|
SelfRef,
|
|
#[sea_orm(entity = "Entity", def = "Relation::SelfRef.def().rev()")]
|
|
SelfRefReverse,
|
|
#[sea_orm(entity = "super::filling::Entity")]
|
|
Filling
|
|
}
|