DeriveEntityModel
automatically derive DeriveModel
and DeriveActiveModel
This commit is contained in:
parent
c0a77c1298
commit
54bb358cca
@ -1,6 +1,6 @@
|
|||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, DeriveModel, DeriveActiveModel)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
#[sea_orm(table_name = "cake")]
|
#[sea_orm(table_name = "cake")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
|
@ -16,6 +16,7 @@ pub fn derive_entity(input: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
#[proc_macro_derive(DeriveEntityModel, attributes(sea_orm))]
|
#[proc_macro_derive(DeriveEntityModel, attributes(sea_orm))]
|
||||||
pub fn derive_entity_model(input: TokenStream) -> TokenStream {
|
pub fn derive_entity_model(input: TokenStream) -> TokenStream {
|
||||||
|
let input_ts = input.clone();
|
||||||
let DeriveInput {
|
let DeriveInput {
|
||||||
ident, data, attrs, ..
|
ident, data, attrs, ..
|
||||||
} = parse_macro_input!(input as DeriveInput);
|
} = parse_macro_input!(input as DeriveInput);
|
||||||
@ -24,10 +25,14 @@ pub fn derive_entity_model(input: TokenStream) -> TokenStream {
|
|||||||
panic!("Struct name must be Model");
|
panic!("Struct name must be Model");
|
||||||
}
|
}
|
||||||
|
|
||||||
match derives::expand_derive_entity_model(data, attrs) {
|
let mut ts: TokenStream = derives::expand_derive_entity_model(data, attrs)
|
||||||
Ok(ts) => ts.into(),
|
.unwrap_or_else(Error::into_compile_error)
|
||||||
Err(e) => e.to_compile_error().into(),
|
.into();
|
||||||
}
|
ts.extend(vec![
|
||||||
|
derive_model(input_ts.clone()),
|
||||||
|
derive_active_model(input_ts),
|
||||||
|
]);
|
||||||
|
ts
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_derive(DerivePrimaryKey)]
|
#[proc_macro_derive(DerivePrimaryKey)]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate as sea_orm;
|
use crate as sea_orm;
|
||||||
use crate::entity::prelude::*;
|
use crate::entity::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, DeriveModel, DeriveActiveModel)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
#[sea_orm(table_name = "cake")]
|
#[sea_orm(table_name = "cake")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate as sea_orm;
|
use crate as sea_orm;
|
||||||
use crate::entity::prelude::*;
|
use crate::entity::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, DeriveModel, DeriveActiveModel)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
#[sea_orm(table_name = "fruit")]
|
#[sea_orm(table_name = "fruit")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user