This introduces several things to optionally support automatic derive attributes for `serde::{Deserialize, Serialize}` for the generated models: - introduces a `WithSerde` enum to indicate if Serialize, Deserialize, or even both should be derived from, - adds an optional cli argument `--with-serde [none: default, serialize, deserialize, both]` - adds test harness for both compact and expanded generation
79 lines
1.6 KiB
Rust
79 lines
1.6 KiB
Rust
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0
|
|
|
|
use sea_orm::entity::prelude:: * ;
|
|
use serde::{Deserialize,Serialize};
|
|
|
|
#[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, Serialize, Deserialize)]
|
|
pub struct Model {
|
|
pub id: i32,
|
|
pub name: Option<String> ,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
|
pub enum Column {
|
|
Id,
|
|
Name,
|
|
}
|
|
|
|
#[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,
|
|
}
|
|
|
|
impl ColumnTrait for Column {
|
|
type EntityName = Entity;
|
|
fn def(&self) -> ColumnDef {
|
|
match self {
|
|
Self::Id => ColumnType::Integer.def(),
|
|
Self::Name => ColumnType::Text.def().null(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl RelationTrait for Relation {
|
|
fn def(&self) -> RelationDef {
|
|
match self {
|
|
Self::Fruit => Entity::has_many(super::fruit::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 {}
|