diff --git a/examples/sqlx-mysql/Cargo.toml b/examples/sqlx-mysql/Cargo.toml index ee0478bb..d2516bc7 100644 --- a/examples/sqlx-mysql/Cargo.toml +++ b/examples/sqlx-mysql/Cargo.toml @@ -7,5 +7,5 @@ publish = false [dependencies] async-std = { version = "^1.9", features = [ "attributes" ] } sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "debug-print" ] } -sea-query = { path = "../../../sea-query" } +# sea-query = { path = "../../../sea-query" } strum = { version = "^0.20", features = [ "derive" ] } \ No newline at end of file diff --git a/examples/sqlx-mysql/src/example_cake.rs b/examples/sqlx-mysql/src/example_cake.rs index f532770d..0f3e92a0 100644 --- a/examples/sqlx-mysql/src/example_cake.rs +++ b/examples/sqlx-mysql/src/example_cake.rs @@ -35,6 +35,40 @@ impl EntityTrait for Entity { type Relation = Relation; } +impl ColumnTrait for Column { + type EntityName = Entity; + + fn def(&self) -> ColumnType { + match self { + Self::Id => ColumnType::Integer(None), + Self::Name => ColumnType::String(None), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Fruit => Entity::has_many(super::fruit::Entity) + .from(Column::Id) + .to(super::fruit::Column::CakeId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Fruit.def() + } +} + +impl Model { + pub fn find_fruit(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + // TODO: implement with derive macro impl EntityName for Entity {} @@ -95,17 +129,6 @@ impl IdenStatic for Column { } } -impl ColumnTrait for Column { - type EntityName = Entity; - - fn def(&self) -> ColumnType { - match self { - Self::Id => ColumnType::Integer(None), - Self::Name => ColumnType::String(None), - } - } -} - // TODO: implement with derive macro impl Iden for PrimaryKey { fn unquoted(&self, s: &mut dyn std::fmt::Write) { @@ -132,27 +155,4 @@ impl PrimaryKeyOfModel for PrimaryKey { Self::Id => Column::Id, } } -} - -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - match self { - Self::Fruit => Entity::has_many(super::fruit::Entity) - .from(Column::Id) - .to(super::fruit::Column::CakeId) - .into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Fruit.def() - } -} - -impl Model { - pub fn find_fruit(&self) -> Select { - Entity::find_related().belongs_to::(self) - } -} +} \ No newline at end of file diff --git a/examples/sqlx-mysql/src/example_fruit.rs b/examples/sqlx-mysql/src/example_fruit.rs index 5164e255..d41ea685 100644 --- a/examples/sqlx-mysql/src/example_fruit.rs +++ b/examples/sqlx-mysql/src/example_fruit.rs @@ -35,6 +35,24 @@ impl EntityTrait for Entity { type Relation = Relation; } +impl ColumnTrait for Column { + type EntityName = Entity; + + fn def(&self) -> ColumnType { + match self { + Self::Id => ColumnType::Integer(None), + Self::Name => ColumnType::String(None), + Self::CakeId => ColumnType::Integer(None), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!() + } +} + // TODO: implement with derive macro impl EntityName for Entity {} @@ -99,17 +117,6 @@ impl IdenStatic for Column { } } -impl ColumnTrait for Column { - type EntityName = Entity; - - fn def(&self) -> ColumnType { - match self { - Self::Id => ColumnType::Integer(None), - Self::Name => ColumnType::String(None), - Self::CakeId => ColumnType::Integer(None), - } - } -} // TODO: implement with derive macro impl Iden for PrimaryKey { @@ -137,10 +144,4 @@ impl PrimaryKeyOfModel for PrimaryKey { Self::Id => Column::Id, } } -} - -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!() - } -} +} \ No newline at end of file diff --git a/src/tests_cfg/cake.rs b/src/tests_cfg/cake.rs index 456074b6..99174199 100644 --- a/src/tests_cfg/cake.rs +++ b/src/tests_cfg/cake.rs @@ -35,6 +35,40 @@ impl EntityTrait for Entity { type Relation = Relation; } +impl ColumnTrait for Column { + type EntityName = Entity; + + fn def(&self) -> ColumnType { + match self { + Self::Id => ColumnType::Integer(None), + Self::Name => ColumnType::String(None), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Fruit => Entity::has_many(super::fruit::Entity) + .from(Column::Id) + .to(super::fruit::Column::CakeId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Fruit.def() + } +} + +impl Model { + pub fn find_fruit(&self) -> Select { + Entity::find_related().belongs_to::(self) + } +} + // TODO: implement with derive macro impl EntityName for Entity {} @@ -95,17 +129,6 @@ impl IdenStatic for Column { } } -impl ColumnTrait for Column { - type EntityName = Entity; - - fn def(&self) -> ColumnType { - match self { - Self::Id => ColumnType::Integer(None), - Self::Name => ColumnType::String(None), - } - } -} - // TODO: implement with derive macro impl Iden for PrimaryKey { fn unquoted(&self, s: &mut dyn std::fmt::Write) { @@ -132,27 +155,4 @@ impl PrimaryKeyOfModel for PrimaryKey { Self::Id => Column::Id, } } -} - -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - match self { - Self::Fruit => Entity::has_many(super::fruit::Entity) - .from(Column::Id) - .to(super::fruit::Column::CakeId) - .into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Fruit.def() - } -} - -impl Model { - pub fn find_fruit(&self) -> Select { - Entity::find_related().belongs_to::(self) - } -} +} \ No newline at end of file diff --git a/src/tests_cfg/fruit.rs b/src/tests_cfg/fruit.rs index e83834d2..e29b6f58 100644 --- a/src/tests_cfg/fruit.rs +++ b/src/tests_cfg/fruit.rs @@ -35,6 +35,24 @@ impl EntityTrait for Entity { type Relation = Relation; } +impl ColumnTrait for Column { + type EntityName = Entity; + + fn def(&self) -> ColumnType { + match self { + Self::Id => ColumnType::Integer(None), + Self::Name => ColumnType::String(None), + Self::CakeId => ColumnType::Integer(None), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!() + } +} + // TODO: implement with derive macro impl EntityName for Entity {} @@ -99,17 +117,6 @@ impl IdenStatic for Column { } } -impl ColumnTrait for Column { - type EntityName = Entity; - - fn def(&self) -> ColumnType { - match self { - Self::Id => ColumnType::Integer(None), - Self::Name => ColumnType::String(None), - Self::CakeId => ColumnType::Integer(None), - } - } -} // TODO: implement with derive macro impl Iden for PrimaryKey { @@ -137,10 +144,4 @@ impl PrimaryKeyOfModel for PrimaryKey { Self::Id => Column::Id, } } -} - -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!() - } -} +} \ No newline at end of file