Use compact Entity format
This commit is contained in:
parent
f7b42ebc0e
commit
6d9727050e
@ -1,65 +1,17 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
|
||||||
#[serde(crate = "serde")]
|
#[sea_orm(table_name = "posts")]
|
||||||
pub struct Entity;
|
|
||||||
|
|
||||||
impl EntityName for Entity {
|
|
||||||
fn table_name(&self) -> &str {
|
|
||||||
"posts"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Deserialize, Serialize,
|
|
||||||
)]
|
|
||||||
#[serde(crate = "serde")]
|
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[serde(skip_deserializing, skip_serializing_if = "Option::is_none")]
|
#[sea_orm(primary_key)]
|
||||||
pub id: Option<i32>,
|
#[serde(skip_deserializing)]
|
||||||
|
pub id: i32,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Column {
|
|
||||||
Id,
|
|
||||||
Title,
|
|
||||||
Text,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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 {}
|
pub enum Relation {}
|
||||||
|
|
||||||
impl ColumnTrait for Column {
|
|
||||||
type EntityName = Entity;
|
|
||||||
|
|
||||||
fn def(&self) -> ColumnDef {
|
|
||||||
match self {
|
|
||||||
Self::Id => ColumnType::Integer.def(),
|
|
||||||
Self::Title => ColumnType::String(None).def(),
|
|
||||||
Self::Text => ColumnType::String(None).def(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelationTrait for Relation {
|
|
||||||
fn def(&self) -> RelationDef {
|
|
||||||
panic!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user