Try DeriveEntity

This commit is contained in:
Chris Tsang 2021-09-07 21:53:09 +08:00
parent 455fc4a934
commit 46d9fd30e6
3 changed files with 4 additions and 9 deletions

View File

@ -2,7 +2,7 @@ pub mod derive_attr {
use bae::FromAttributes; use bae::FromAttributes;
#[derive(Default, FromAttributes)] #[derive(Default, FromAttributes)]
pub struct Sea { pub struct SeaOrm {
pub column: Option<syn::Ident>, pub column: Option<syn::Ident>,
pub entity: Option<syn::Ident>, pub entity: Option<syn::Ident>,
pub model: Option<syn::Ident>, pub model: Option<syn::Ident>,
@ -17,7 +17,7 @@ pub mod field_attr {
use bae::FromAttributes; use bae::FromAttributes;
#[derive(Default, FromAttributes)] #[derive(Default, FromAttributes)]
pub struct Sea { pub struct SeaOrm {
pub auto_increment: Option<syn::Lit>, pub auto_increment: Option<syn::Lit>,
pub belongs_to: Option<syn::Lit>, pub belongs_to: Option<syn::Lit>,
pub column_type: Option<syn::Lit>, pub column_type: Option<syn::Lit>,

View File

@ -17,7 +17,7 @@ struct DeriveEntity {
impl DeriveEntity { impl DeriveEntity {
fn new(input: syn::DeriveInput) -> Result<Self, syn::Error> { fn new(input: syn::DeriveInput) -> Result<Self, syn::Error> {
let sea_attr = derive_attr::Sea::try_from_attributes(&input.attrs)?.unwrap_or_default(); let sea_attr = derive_attr::SeaOrm::try_from_attributes(&input.attrs)?.unwrap_or_default();
let ident = input.ident; let ident = input.ident;
let column_ident = sea_attr.column.unwrap_or_else(|| format_ident!("Column")); let column_ident = sea_attr.column.unwrap_or_else(|| format_ident!("Column"));

View File

@ -2,14 +2,9 @@ use crate as sea_orm;
use crate::entity::prelude::*; use crate::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)] #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
#[sea_orm(table_name = "fruit")]
pub struct Entity; pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"fruit"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model { pub struct Model {
pub id: i32, pub id: i32,