From 0c4b69e3b3d4f66b6a0bde52602770f13f281505 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Wed, 19 May 2021 20:07:57 +0800 Subject: [PATCH] impl EntityTrait --- examples/sqlx-mysql/src/example_cake.rs | 10 ---------- examples/sqlx-mysql/src/example_cake_filling.rs | 10 ---------- examples/sqlx-mysql/src/example_filling.rs | 10 ---------- examples/sqlx-mysql/src/example_fruit.rs | 10 ---------- sea-orm-macros/src/derives/entity.rs | 10 ++++++++++ src/tests_cfg/cake.rs | 10 ---------- src/tests_cfg/cake_filling.rs | 10 ---------- src/tests_cfg/filling.rs | 10 ---------- src/tests_cfg/fruit.rs | 10 ---------- 9 files changed, 10 insertions(+), 80 deletions(-) diff --git a/examples/sqlx-mysql/src/example_cake.rs b/examples/sqlx-mysql/src/example_cake.rs index bbb5e09f..d8c43a10 100644 --- a/examples/sqlx-mysql/src/example_cake.rs +++ b/examples/sqlx-mysql/src/example_cake.rs @@ -27,16 +27,6 @@ pub enum Relation { CakeFilling, } -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/examples/sqlx-mysql/src/example_cake_filling.rs b/examples/sqlx-mysql/src/example_cake_filling.rs index c174f72b..66dad79a 100644 --- a/examples/sqlx-mysql/src/example_cake_filling.rs +++ b/examples/sqlx-mysql/src/example_cake_filling.rs @@ -28,16 +28,6 @@ pub enum Relation { Filling, } -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/examples/sqlx-mysql/src/example_filling.rs b/examples/sqlx-mysql/src/example_filling.rs index 76fcd066..faa2872a 100644 --- a/examples/sqlx-mysql/src/example_filling.rs +++ b/examples/sqlx-mysql/src/example_filling.rs @@ -24,16 +24,6 @@ pub enum PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation {} -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/examples/sqlx-mysql/src/example_fruit.rs b/examples/sqlx-mysql/src/example_fruit.rs index 340dfbd8..d347f50e 100644 --- a/examples/sqlx-mysql/src/example_fruit.rs +++ b/examples/sqlx-mysql/src/example_fruit.rs @@ -26,16 +26,6 @@ pub enum PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation {} -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/sea-orm-macros/src/derives/entity.rs b/sea-orm-macros/src/derives/entity.rs index 8dd7b046..2f4898f2 100644 --- a/sea-orm-macros/src/derives/entity.rs +++ b/sea-orm-macros/src/derives/entity.rs @@ -39,5 +39,15 @@ pub fn expend_derive_entity(ident: Ident, attrs: Vec) -> syn::Result< write!(s, "{}", self.as_str()).unwrap(); } } + + impl EntityTrait for #ident { + type Model = Model; + + type Column = Column; + + type PrimaryKey = PrimaryKey; + + type Relation = Relation; + } )) } diff --git a/src/tests_cfg/cake.rs b/src/tests_cfg/cake.rs index 40dd5bd8..d8fb319d 100644 --- a/src/tests_cfg/cake.rs +++ b/src/tests_cfg/cake.rs @@ -28,16 +28,6 @@ pub enum Relation { CakeFilling, } -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/src/tests_cfg/cake_filling.rs b/src/tests_cfg/cake_filling.rs index 8659d8ad..c9058e78 100644 --- a/src/tests_cfg/cake_filling.rs +++ b/src/tests_cfg/cake_filling.rs @@ -29,16 +29,6 @@ pub enum Relation { Filling, } -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/src/tests_cfg/filling.rs b/src/tests_cfg/filling.rs index 50ff9cca..ee51b5b4 100644 --- a/src/tests_cfg/filling.rs +++ b/src/tests_cfg/filling.rs @@ -25,16 +25,6 @@ pub enum PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation {} -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity; diff --git a/src/tests_cfg/fruit.rs b/src/tests_cfg/fruit.rs index 923af3fe..23a274c3 100644 --- a/src/tests_cfg/fruit.rs +++ b/src/tests_cfg/fruit.rs @@ -27,16 +27,6 @@ pub enum PrimaryKey { #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation {} -impl EntityTrait for Entity { - type Model = Model; - - type Column = Column; - - type PrimaryKey = PrimaryKey; - - type Relation = Relation; -} - impl ColumnTrait for Column { type EntityName = Entity;