diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0f3a137c..accf13ba 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -95,13 +95,13 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.11.0' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/sqlite/src - name: Copy sample database run: cp ./examples/sqlite/sakila.db . - name: Generate entities - run: sea-orm-cli generate entity -o examples/sqlite/src/entities -u sqlite://sakila.db + run: sea-orm-cli generate entity -o examples/sqlite/src/entities -u sqlite://sakila.db --seaography - name: Generate Seaography project uses: actions-rs/cargo@v1 with: @@ -135,13 +135,13 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.11.0' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/sqlite/src - name: Copy sample database run: cp ./examples/sqlite/sakila.db . - name: Generate entities - run: sea-orm-cli generate entity -o examples/sqlite/src/entities -u sqlite://sakila.db + run: sea-orm-cli generate entity -o examples/sqlite/src/entities -u sqlite://sakila.db --seaography - name: Generate Seaography project uses: actions-rs/cargo@v1 with: @@ -190,7 +190,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.11.0' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/mysql/src - name: Create DB @@ -204,7 +204,7 @@ jobs: run: mysql -uroot -h 127.0.0.1 sakila < sakila-data.sql working-directory: ./examples/mysql - name: Generate entities - run: sea-orm-cli generate entity -o ./examples/mysql/src/entities -u mysql://sea:sea@127.0.0.1/sakila + run: sea-orm-cli generate entity -o ./examples/mysql/src/entities -u mysql://sea:sea@127.0.0.1/sakila --seaography - name: Generate Seaography project uses: actions-rs/cargo@v1 with: @@ -252,7 +252,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.11.0' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/postgres/src - name: Create DB @@ -264,7 +264,7 @@ jobs: run: psql -q postgres://sea:sea@localhost/sakila < sakila-data.sql working-directory: ./examples/postgres - name: Generate entities - run: sea-orm-cli generate entity -o ./examples/postgres/src/entities -u postgres://sea:sea@127.0.0.1/sakila?currentSchema=public + run: sea-orm-cli generate entity -o ./examples/postgres/src/entities -u postgres://sea:sea@127.0.0.1/sakila?currentSchema=public --seaography - name: Generate Seaography project uses: actions-rs/cargo@v1 with: @@ -275,7 +275,7 @@ jobs: - name: Depends on local seaography run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/postgres/Cargo.toml - name: Fix Nullable not implemented for Vec and tsvector - run: sed -i "25,27d" ./examples/postgres/src/entities/film.rs + run: sed -i "26,27d" ./examples/postgres/src/entities/film.rs - name: Build example working-directory: ./examples/postgres run: cargo build diff --git a/Cargo.toml b/Cargo.toml index 9f4b96ce..09c16e74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ keywords = ["async", "graphql", "mysql", "postgres", "sqlite"] categories = ["database"] [dependencies] -async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -sea-orm = { version = "0.11.0", default-features = false } -itertools = { version = "0.10.5" } +async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } +sea-orm = { version = "0.12.0-rc.5", default-features = false, features = ["seaography"] } +itertools = { version = "0.11.0" } heck = { version = "0.4.1" } [features] diff --git a/README.md b/README.md index 6622f522..9a44825c 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Setup the [sakila](https://github.com/SeaQL/seaography/blob/main/examples/mysql/ ```sh cd examples/mysql -sea-orm-cli generate entity -o src/entities -u mysql://user:pw@127.0.0.1/sakila +sea-orm-cli generate entity -o src/entities -u mysql://user:pw@127.0.0.1/sakila --seaography seaography-cli ./ src/entities mysql://user:pw@127.0.0.1/sakila seaography-mysql-example cargo run ``` @@ -205,7 +205,7 @@ Setup the [sakila](https://github.com/SeaQL/seaography/blob/main/examples/postgr ```sh cd examples/postgres -sea-orm-cli generate entity -o src/entities -u postgres://user:pw@localhost/sakila +sea-orm-cli generate entity -o src/entities -u postgres://user:pw@localhost/sakila --seaography seaography-cli ./ src/entities postgres://user:pw@localhost/sakila seaography-postgres-example cargo run ``` @@ -214,7 +214,7 @@ cargo run ```sh cd examples/sqlite -sea-orm-cli generate entity -o src/entities -u sqlite://sakila.db +sea-orm-cli generate entity -o src/entities -u sqlite://sakila.db --seaography seaography-cli ./ src/entities sqlite://sakila.db seaography-sqlite-example cargo run ``` diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d87b5ffe..0db47f74 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -14,6 +14,6 @@ categories = ["database"] [dependencies] async-std = { version = "1.12.0", features = [ "attributes", "tokio1" ] } -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.3.19", features = ["derive"] } seaography-generator = { version = "^1.0.0", path = "../generator" } -url = "2.3.1" \ No newline at end of file +url = "2.4.0" \ No newline at end of file diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml index 88a05fbd..4aa43e5b 100644 --- a/examples/mysql/Cargo.toml +++ b/examples/mysql/Cargo.toml @@ -4,24 +4,24 @@ name = "seaography-mysql-example" version = "0.3.0" [dependencies] -poem = { version = "1.3.55" } -async-graphql-poem = { version = "5.0.6" } -async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -async-trait = { version = "0.1.64" } +poem = { version = "1.3.56" } +async-graphql-poem = { version = "5.0.10" } +async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } +async-trait = { version = "0.1.72" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["sqlx-mysql", "runtime-async-std-native-tls"] } -tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } +sea-orm = { version = "0.12.0-rc.5", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] } +tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } -tracing-subscriber = { version = "0.3.16" } +tracing-subscriber = { version = "0.3.17" } lazy_static = { version = "1.4.0" } [dependencies.seaography] -path = "../../" # remove this line in your own project +path = "../../" version = "^1.0.0" # seaography version features = ["with-decimal", "with-chrono"] [dev-dependencies] -serde_json = { version = "1.0.82" } +serde_json = { version = "1.0.103" } [workspace] members = [] \ No newline at end of file diff --git a/examples/mysql/src/entities/actor.rs b/examples/mysql/src/entities/actor.rs index ff14665f..049a4113 100644 --- a/examples/mysql/src/entities/actor.rs +++ b/examples/mysql/src/entities/actor.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -13,7 +13,16 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} impl Related for Entity { fn to() -> RelationDef { @@ -25,3 +34,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/mysql/src/entities/address.rs b/examples/mysql/src/entities/address.rs index 0a721e31..d1e5a0ab 100644 --- a/examples/mysql/src/entities/address.rs +++ b/examples/mysql/src/entities/address.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -13,6 +13,7 @@ pub struct Model { pub city_id: i32, pub postal_code: Option, pub phone: String, + #[sea_orm(column_type = "VarBinary(25)", nullable)] pub location: Option>, pub last_update: DateTimeUtc, } @@ -60,3 +61,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::city::Entity")] + City, + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::staff::Entity")] + Staff, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/mysql/src/entities/category.rs b/examples/mysql/src/entities/category.rs index 6907b636..7eaf7e7e 100644 --- a/examples/mysql/src/entities/category.rs +++ b/examples/mysql/src/entities/category.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -12,7 +12,16 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} impl Related for Entity { fn to() -> RelationDef { @@ -24,3 +33,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_category::Entity")] + FilmCategory, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/mysql/src/entities/city.rs b/examples/mysql/src/entities/city.rs index 93449c1c..aee384e6 100644 --- a/examples/mysql/src/entities/city.rs +++ b/examples/mysql/src/entities/city.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -39,3 +39,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::country::Entity")] + Country, +} diff --git a/examples/mysql/src/entities/country.rs b/examples/mysql/src/entities/country.rs index 778e709c..46a40349 100644 --- a/examples/mysql/src/entities/country.rs +++ b/examples/mysql/src/entities/country.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -24,3 +24,9 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::city::Entity")] + City, +} diff --git a/examples/mysql/src/entities/customer.rs b/examples/mysql/src/entities/customer.rs index 11485b30..f7c59851 100644 --- a/examples/mysql/src/entities/customer.rs +++ b/examples/mysql/src/entities/customer.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -66,3 +66,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/mysql/src/entities/film.rs b/examples/mysql/src/entities/film.rs index 11e568b2..284d308e 100644 --- a/examples/mysql/src/entities/film.rs +++ b/examples/mysql/src/entities/film.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use super::sea_orm_active_enums::Rating; use sea_orm::entity::prelude::*; @@ -31,6 +31,10 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, #[sea_orm(has_many = "super::inventory::Entity")] Inventory, #[sea_orm( @@ -51,6 +55,18 @@ pub enum Relation { Language1, } +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::Inventory.def() @@ -76,3 +92,21 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(entity = "super::film_category::Entity")] + FilmCategory, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::language::Entity", def = "Relation::Language2.def()")] + Language2, + #[sea_orm(entity = "super::language::Entity", def = "Relation::Language1.def()")] + Language1, + #[sea_orm(entity = "super::actor::Entity")] + Actor, + #[sea_orm(entity = "super::category::Entity")] + Category, +} diff --git a/examples/mysql/src/entities/film_actor.rs b/examples/mysql/src/entities/film_actor.rs index 0f329afb..cc0cacf8 100644 --- a/examples/mysql/src/entities/film_actor.rs +++ b/examples/mysql/src/entities/film_actor.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -45,3 +45,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::actor::Entity")] + Actor, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/mysql/src/entities/film_category.rs b/examples/mysql/src/entities/film_category.rs index 09585943..1ffc02e3 100644 --- a/examples/mysql/src/entities/film_category.rs +++ b/examples/mysql/src/entities/film_category.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -45,3 +45,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::category::Entity")] + Category, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/mysql/src/entities/film_text.rs b/examples/mysql/src/entities/film_text.rs index 3898cfac..df005546 100644 --- a/examples/mysql/src/entities/film_text.rs +++ b/examples/mysql/src/entities/film_text.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -16,3 +16,6 @@ pub struct Model { pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity {} diff --git a/examples/mysql/src/entities/inventory.rs b/examples/mysql/src/entities/inventory.rs index 330675dc..f483f722 100644 --- a/examples/mysql/src/entities/inventory.rs +++ b/examples/mysql/src/entities/inventory.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -53,3 +53,13 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film::Entity")] + Film, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/mysql/src/entities/language.rs b/examples/mysql/src/entities/language.rs index e64290ae..6fe0690f 100644 --- a/examples/mysql/src/entities/language.rs +++ b/examples/mysql/src/entities/language.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -15,3 +15,6 @@ pub struct Model { pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity {} diff --git a/examples/mysql/src/entities/mod.rs b/examples/mysql/src/entities/mod.rs index 68e78f4e..d71df32a 100644 --- a/examples/mysql/src/entities/mod.rs +++ b/examples/mysql/src/entities/mod.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 pub mod prelude; diff --git a/examples/mysql/src/entities/payment.rs b/examples/mysql/src/entities/payment.rs index 638f488a..60e71fd4 100644 --- a/examples/mysql/src/entities/payment.rs +++ b/examples/mysql/src/entities/payment.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -63,3 +63,13 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/mysql/src/entities/prelude.rs b/examples/mysql/src/entities/prelude.rs index 8c1f2aac..3b2c48d9 100644 --- a/examples/mysql/src/entities/prelude.rs +++ b/examples/mysql/src/entities/prelude.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 pub use super::actor::Entity as Actor; pub use super::address::Entity as Address; diff --git a/examples/mysql/src/entities/rental.rs b/examples/mysql/src/entities/rental.rs index e377aa67..18d4e312 100644 --- a/examples/mysql/src/entities/rental.rs +++ b/examples/mysql/src/entities/rental.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -70,3 +70,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/mysql/src/entities/sea_orm_active_enums.rs b/examples/mysql/src/entities/sea_orm_active_enums.rs index 9c5c4e40..efc9020d 100644 --- a/examples/mysql/src/entities/sea_orm_active_enums.rs +++ b/examples/mysql/src/entities/sea_orm_active_enums.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/mysql/src/entities/staff.rs b/examples/mysql/src/entities/staff.rs index 73572f09..58d4738f 100644 --- a/examples/mysql/src/entities/staff.rs +++ b/examples/mysql/src/entities/staff.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -11,6 +11,7 @@ pub struct Model { pub last_name: String, pub address_id: i32, pub reports_to_id: Option, + #[sea_orm(column_type = "Binary(BlobSize::Blob(None))", nullable)] pub picture: Option>, pub email: Option, pub store_id: i32, @@ -77,3 +78,19 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "Entity", def = "Relation::SelfRef.def()")] + SelfRef, + #[sea_orm(entity = "super::store::Entity")] + Store, + #[sea_orm(entity = "Entity", def = "Relation::SelfRef.def().rev()")] + SelfRefReverse, +} diff --git a/examples/mysql/src/entities/store.rs b/examples/mysql/src/entities/store.rs index abd0007e..384aa5c6 100644 --- a/examples/mysql/src/entities/store.rs +++ b/examples/mysql/src/entities/store.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -62,3 +62,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/mysql/src/main.rs b/examples/mysql/src/main.rs index d5244148..025319e1 100644 --- a/examples/mysql/src/main.rs +++ b/examples/mysql/src/main.rs @@ -26,7 +26,7 @@ lazy_static! { #[handler] async fn graphql_playground() -> impl IntoResponse { - Html(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT))) + Html(playground_source(GraphQLPlaygroundConfig::new(&ENDPOINT))) } #[tokio::main] diff --git a/examples/mysql/src/query_root.rs b/examples/mysql/src/query_root.rs index d8700e8c..408d2132 100644 --- a/examples/mysql/src/query_root.rs +++ b/examples/mysql/src/query_root.rs @@ -1,9 +1,7 @@ -use crate::OrmDataloader; +use crate::{entities::*, OrmDataloader}; use async_graphql::{dataloader::DataLoader, dynamic::*}; -use sea_orm::{DatabaseConnection, RelationTrait}; -use seaography::{ - Builder, BuilderContext, EntityObjectRelationBuilder, EntityObjectViaRelationBuilder, -}; +use sea_orm::DatabaseConnection; +use seaography::{Builder, BuilderContext}; lazy_static::lazy_static! { static ref CONTEXT : BuilderContext = BuilderContext :: default () ; } @@ -14,229 +12,27 @@ pub fn schema( complexity: Option, ) -> Result { let mut builder = Builder::new(&CONTEXT); - let entity_object_relation_builder = EntityObjectRelationBuilder { context: &CONTEXT }; - let entity_object_via_relation_builder = EntityObjectViaRelationBuilder { context: &CONTEXT }; - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "actor", - crate::entities::film_actor::Relation::Actor.def(), - ), - entity_object_relation_builder - .get_relation::( - "film", - crate::entities::film_actor::Relation::Film.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::rental::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::rental::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::rental::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::rental::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::( - "film", - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::staff::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::staff::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::staff::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "selfRef", - crate::entities::staff::Relation::SelfRef.def(), - ), - entity_object_relation_builder - .get_relation::( - "selfRefReverse", - crate::entities::staff::Relation::SelfRef.def().rev(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::staff::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "city", - crate::entities::country::Relation::City.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::("actor"), - entity_object_via_relation_builder - .get_relation::( - "category", - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::film::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "language1", - crate::entities::film::Relation::Language1.def(), - ), - entity_object_relation_builder - .get_relation::( - "language2", - crate::entities::film::Relation::Language2.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::("film"), - ]); - builder.register_entity::(vec![]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::city::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "country", - crate::entities::city::Relation::Country.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "film", - crate::entities::inventory::Relation::Film.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::inventory::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::inventory::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![]); - builder . register_entity :: < crate :: entities :: film_category :: Entity > (vec ! [entity_object_relation_builder . get_relation :: < crate :: entities :: film_category :: Entity , crate :: entities :: category :: Entity > ("category" , crate :: entities :: film_category :: Relation :: Category . def ()) , entity_object_relation_builder . get_relation :: < crate :: entities :: film_category :: Entity , crate :: entities :: film :: Entity > ("film" , crate :: entities :: film_category :: Relation :: Film . def ())]) ; - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::customer::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::customer::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::customer::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::customer::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::store::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::store::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::store::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::store::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::payment::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::payment::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::payment::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "city", - crate::entities::address::Relation::City.def(), - ), - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::address::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::address::Relation::Staff.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::address::Relation::Store.def(), - ), - ]); + seaography::register_entities!( + builder, + [ + film_actor, + rental, + category, + staff, + country, + film, + actor, + language, + city, + inventory, + film_text, + film_category, + customer, + store, + payment, + address, + ] + ); builder.register_enumeration::(); let schema = builder.schema_builder(); let schema = if let Some(depth) = depth { diff --git a/examples/postgres/Cargo.toml b/examples/postgres/Cargo.toml index 49f298e1..510a6452 100644 --- a/examples/postgres/Cargo.toml +++ b/examples/postgres/Cargo.toml @@ -4,24 +4,24 @@ name = "seaography-postgres-example" version = "0.3.0" [dependencies] -poem = { version = "1.3.55" } -async-graphql-poem = { version = "5.0.6" } -async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -async-trait = { version = "0.1.64" } +poem = { version = "1.3.56" } +async-graphql-poem = { version = "5.0.10" } +async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } +async-trait = { version = "0.1.72" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["sqlx-postgres", "runtime-async-std-native-tls"] } -tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } +sea-orm = { version = "0.12.0-rc.5", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] } +tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } -tracing-subscriber = { version = "0.3.16" } +tracing-subscriber = { version = "0.3.17" } lazy_static = { version = "1.4.0" } [dependencies.seaography] +path = "../../" version = "^1.0.0" # seaography version -path = "../../" # remove this line in your own project features = ["with-decimal", "with-chrono"] [dev-dependencies] -serde_json = { version = "1.0.82" } +serde_json = { version = "1.0.103" } [workspace] members = [] \ No newline at end of file diff --git a/examples/postgres/src/entities/actor.rs b/examples/postgres/src/entities/actor.rs index ed2d47ad..95ecb50c 100644 --- a/examples/postgres/src/entities/actor.rs +++ b/examples/postgres/src/entities/actor.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -13,7 +13,16 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} impl Related for Entity { fn to() -> RelationDef { @@ -25,3 +34,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/postgres/src/entities/address.rs b/examples/postgres/src/entities/address.rs index 5f8d67d5..d217864f 100644 --- a/examples/postgres/src/entities/address.rs +++ b/examples/postgres/src/entities/address.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -59,3 +59,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::city::Entity")] + City, + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::staff::Entity")] + Staff, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/postgres/src/entities/category.rs b/examples/postgres/src/entities/category.rs index 8f5ba647..6cbc9cd8 100644 --- a/examples/postgres/src/entities/category.rs +++ b/examples/postgres/src/entities/category.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -12,7 +12,16 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} impl Related for Entity { fn to() -> RelationDef { @@ -24,3 +33,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_category::Entity")] + FilmCategory, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/postgres/src/entities/city.rs b/examples/postgres/src/entities/city.rs index 724f0619..4cf87f89 100644 --- a/examples/postgres/src/entities/city.rs +++ b/examples/postgres/src/entities/city.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -39,3 +39,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::country::Entity")] + Country, +} diff --git a/examples/postgres/src/entities/country.rs b/examples/postgres/src/entities/country.rs index 2e5388a9..4e474d6a 100644 --- a/examples/postgres/src/entities/country.rs +++ b/examples/postgres/src/entities/country.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -24,3 +24,9 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::city::Entity")] + City, +} diff --git a/examples/postgres/src/entities/customer.rs b/examples/postgres/src/entities/customer.rs index d9d41b6e..1cccbfba 100644 --- a/examples/postgres/src/entities/customer.rs +++ b/examples/postgres/src/entities/customer.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -67,3 +67,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/postgres/src/entities/film.rs b/examples/postgres/src/entities/film.rs index 248259ab..5bd84b8c 100644 --- a/examples/postgres/src/entities/film.rs +++ b/examples/postgres/src/entities/film.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use super::sea_orm_active_enums::MpaaRating; use sea_orm::entity::prelude::*; @@ -22,13 +22,15 @@ pub struct Model { pub replacement_cost: Decimal, pub rating: Option, pub last_update: DateTime, -// pub special_features: Option>, -// #[sea_orm(column_type = "custom(\"tsvector\")")] -// pub fulltext: String, + pub special_features: Option>, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, #[sea_orm(has_many = "super::inventory::Entity")] Inventory, #[sea_orm( @@ -49,6 +51,18 @@ pub enum Relation { Language1, } +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::Inventory.def() @@ -74,3 +88,21 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(entity = "super::film_category::Entity")] + FilmCategory, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::language::Entity", def = "Relation::Language2.def()")] + Language2, + #[sea_orm(entity = "super::language::Entity", def = "Relation::Language1.def()")] + Language1, + #[sea_orm(entity = "super::actor::Entity")] + Actor, + #[sea_orm(entity = "super::category::Entity")] + Category, +} diff --git a/examples/postgres/src/entities/film_actor.rs b/examples/postgres/src/entities/film_actor.rs index 882b6f3d..05265226 100644 --- a/examples/postgres/src/entities/film_actor.rs +++ b/examples/postgres/src/entities/film_actor.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -45,3 +45,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::actor::Entity")] + Actor, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/postgres/src/entities/film_category.rs b/examples/postgres/src/entities/film_category.rs index 1207a4a8..ea53140b 100644 --- a/examples/postgres/src/entities/film_category.rs +++ b/examples/postgres/src/entities/film_category.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -45,3 +45,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::category::Entity")] + Category, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/postgres/src/entities/inventory.rs b/examples/postgres/src/entities/inventory.rs index a5328d92..9d4339e1 100644 --- a/examples/postgres/src/entities/inventory.rs +++ b/examples/postgres/src/entities/inventory.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -53,3 +53,13 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film::Entity")] + Film, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/postgres/src/entities/language.rs b/examples/postgres/src/entities/language.rs index 8dc7d276..f937ad8c 100644 --- a/examples/postgres/src/entities/language.rs +++ b/examples/postgres/src/entities/language.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -15,3 +15,6 @@ pub struct Model { pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity {} diff --git a/examples/postgres/src/entities/mod.rs b/examples/postgres/src/entities/mod.rs index d7356287..b139b63c 100644 --- a/examples/postgres/src/entities/mod.rs +++ b/examples/postgres/src/entities/mod.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 pub mod prelude; diff --git a/examples/postgres/src/entities/payment.rs b/examples/postgres/src/entities/payment.rs index a590c444..e4032aa6 100644 --- a/examples/postgres/src/entities/payment.rs +++ b/examples/postgres/src/entities/payment.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -62,3 +62,13 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/postgres/src/entities/prelude.rs b/examples/postgres/src/entities/prelude.rs index 0048a54c..d1ef294f 100644 --- a/examples/postgres/src/entities/prelude.rs +++ b/examples/postgres/src/entities/prelude.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 pub use super::actor::Entity as Actor; pub use super::address::Entity as Address; diff --git a/examples/postgres/src/entities/rental.rs b/examples/postgres/src/entities/rental.rs index 642c5c43..6f1a13ed 100644 --- a/examples/postgres/src/entities/rental.rs +++ b/examples/postgres/src/entities/rental.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -70,3 +70,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/postgres/src/entities/sea_orm_active_enums.rs b/examples/postgres/src/entities/sea_orm_active_enums.rs index ee82cd4f..10c0597f 100644 --- a/examples/postgres/src/entities/sea_orm_active_enums.rs +++ b/examples/postgres/src/entities/sea_orm_active_enums.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/postgres/src/entities/staff.rs b/examples/postgres/src/entities/staff.rs index 3f61badf..83d3ce04 100644 --- a/examples/postgres/src/entities/staff.rs +++ b/examples/postgres/src/entities/staff.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -16,6 +16,7 @@ pub struct Model { pub username: String, pub password: Option, pub last_update: DateTime, + #[sea_orm(column_type = "Binary(BlobSize::Blob(None))", nullable)] pub picture: Option>, } @@ -68,3 +69,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/postgres/src/entities/store.rs b/examples/postgres/src/entities/store.rs index 6d799657..ff498e7b 100644 --- a/examples/postgres/src/entities/store.rs +++ b/examples/postgres/src/entities/store.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -61,3 +61,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/postgres/src/main.rs b/examples/postgres/src/main.rs index 16810b4e..127a9710 100644 --- a/examples/postgres/src/main.rs +++ b/examples/postgres/src/main.rs @@ -26,7 +26,7 @@ lazy_static! { #[handler] async fn graphql_playground() -> impl IntoResponse { - Html(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT))) + Html(playground_source(GraphQLPlaygroundConfig::new(&ENDPOINT))) } #[tokio::main] diff --git a/examples/postgres/src/query_root.rs b/examples/postgres/src/query_root.rs index b9ab8302..cd4d19d4 100644 --- a/examples/postgres/src/query_root.rs +++ b/examples/postgres/src/query_root.rs @@ -1,9 +1,7 @@ -use crate::OrmDataloader; +use crate::{entities::*, OrmDataloader}; use async_graphql::{dataloader::DataLoader, dynamic::*}; -use sea_orm::{DatabaseConnection, RelationTrait}; -use seaography::{ - Builder, BuilderContext, EntityObjectRelationBuilder, EntityObjectViaRelationBuilder, -}; +use sea_orm::DatabaseConnection; +use seaography::{Builder, BuilderContext}; lazy_static::lazy_static! { static ref CONTEXT : BuilderContext = BuilderContext :: default () ; } @@ -14,218 +12,26 @@ pub fn schema( complexity: Option, ) -> Result { let mut builder = Builder::new(&CONTEXT); - let entity_object_relation_builder = EntityObjectRelationBuilder { context: &CONTEXT }; - let entity_object_via_relation_builder = EntityObjectViaRelationBuilder { context: &CONTEXT }; - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "actor", - crate::entities::film_actor::Relation::Actor.def(), - ), - entity_object_relation_builder - .get_relation::( - "film", - crate::entities::film_actor::Relation::Film.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::rental::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::rental::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::rental::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::rental::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::( - "film", - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::staff::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::staff::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::staff::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::staff::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "city", - crate::entities::country::Relation::City.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::("actor"), - entity_object_via_relation_builder - .get_relation::( - "category", - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::film::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "language1", - crate::entities::film::Relation::Language1.def(), - ), - entity_object_relation_builder - .get_relation::( - "language2", - crate::entities::film::Relation::Language2.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::("film"), - ]); - builder.register_entity::(vec![]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::city::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "country", - crate::entities::city::Relation::Country.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "film", - crate::entities::inventory::Relation::Film.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::inventory::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::inventory::Relation::Store.def(), - ), - ]); - builder . register_entity :: < crate :: entities :: film_category :: Entity > (vec ! [entity_object_relation_builder . get_relation :: < crate :: entities :: film_category :: Entity , crate :: entities :: category :: Entity > ("category" , crate :: entities :: film_category :: Relation :: Category . def ()) , entity_object_relation_builder . get_relation :: < crate :: entities :: film_category :: Entity , crate :: entities :: film :: Entity > ("film" , crate :: entities :: film_category :: Relation :: Film . def ())]) ; - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::customer::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::customer::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::customer::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::customer::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::store::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::store::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::store::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::store::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::payment::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::payment::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::payment::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "city", - crate::entities::address::Relation::City.def(), - ), - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::address::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::address::Relation::Staff.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::address::Relation::Store.def(), - ), - ]); + seaography::register_entities!( + builder, + [ + film_actor, + rental, + category, + staff, + country, + film, + actor, + language, + city, + inventory, + film_category, + customer, + store, + payment, + address, + ] + ); builder.register_enumeration::(); let schema = builder.schema_builder(); let schema = if let Some(depth) = depth { diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 8e3098ef..dd8ddba3 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -4,24 +4,24 @@ name = "seaography-sqlite-example" version = "0.3.0" [dependencies] -poem = { version = "1.3.55" } -async-graphql-poem = { version = "5.0.6" } -async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -async-trait = { version = "0.1.64" } +poem = { version = "1.3.56" } +async-graphql-poem = { version = "5.0.10" } +async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } +async-trait = { version = "0.1.72" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["sqlx-sqlite", "runtime-async-std-native-tls"] } -tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } +sea-orm = { version = "0.12.0-rc.5", features = ["sqlx-sqlite", "runtime-async-std-native-tls", "seaography"] } +tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } -tracing-subscriber = { version = "0.3.16" } +tracing-subscriber = { version = "0.3.17" } lazy_static = { version = "1.4.0" } [dependencies.seaography] -path = "../../" # remove this line in your own project +path = "../../" version = "^1.0.0" # seaography version features = ["with-decimal", "with-chrono"] [dev-dependencies] -serde_json = { version = "1.0.82" } +serde_json = { version = "1.0.103" } [workspace] members = [] \ No newline at end of file diff --git a/examples/sqlite/src/entities/actor.rs b/examples/sqlite/src/entities/actor.rs index ff14665f..049a4113 100644 --- a/examples/sqlite/src/entities/actor.rs +++ b/examples/sqlite/src/entities/actor.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -13,7 +13,16 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} impl Related for Entity { fn to() -> RelationDef { @@ -25,3 +34,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/sqlite/src/entities/address.rs b/examples/sqlite/src/entities/address.rs index b9483ed9..2d862899 100644 --- a/examples/sqlite/src/entities/address.rs +++ b/examples/sqlite/src/entities/address.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -59,3 +59,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::city::Entity")] + City, + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::staff::Entity")] + Staff, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/sqlite/src/entities/category.rs b/examples/sqlite/src/entities/category.rs index 0ec69eb5..4f4a445d 100644 --- a/examples/sqlite/src/entities/category.rs +++ b/examples/sqlite/src/entities/category.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -12,7 +12,16 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} impl Related for Entity { fn to() -> RelationDef { @@ -24,3 +33,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_category::Entity")] + FilmCategory, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/sqlite/src/entities/city.rs b/examples/sqlite/src/entities/city.rs index 0eb99e01..0916b863 100644 --- a/examples/sqlite/src/entities/city.rs +++ b/examples/sqlite/src/entities/city.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -39,3 +39,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::country::Entity")] + Country, +} diff --git a/examples/sqlite/src/entities/country.rs b/examples/sqlite/src/entities/country.rs index 2424fbcc..4c79dbd1 100644 --- a/examples/sqlite/src/entities/country.rs +++ b/examples/sqlite/src/entities/country.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -24,3 +24,9 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::city::Entity")] + City, +} diff --git a/examples/sqlite/src/entities/customer.rs b/examples/sqlite/src/entities/customer.rs index 87ef6d62..5c20a25c 100644 --- a/examples/sqlite/src/entities/customer.rs +++ b/examples/sqlite/src/entities/customer.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -66,3 +66,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/sqlite/src/entities/film.rs b/examples/sqlite/src/entities/film.rs index 7a773950..ee6c0abc 100644 --- a/examples/sqlite/src/entities/film.rs +++ b/examples/sqlite/src/entities/film.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -25,6 +25,10 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, #[sea_orm(has_many = "super::inventory::Entity")] Inventory, #[sea_orm( @@ -45,6 +49,18 @@ pub enum Relation { Language1, } +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::Inventory.def() @@ -70,3 +86,21 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film_actor::Entity")] + FilmActor, + #[sea_orm(entity = "super::film_category::Entity")] + FilmCategory, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::language::Entity", def = "Relation::Language2.def()")] + Language2, + #[sea_orm(entity = "super::language::Entity", def = "Relation::Language1.def()")] + Language1, + #[sea_orm(entity = "super::actor::Entity")] + Actor, + #[sea_orm(entity = "super::category::Entity")] + Category, +} diff --git a/examples/sqlite/src/entities/film_actor.rs b/examples/sqlite/src/entities/film_actor.rs index aecce111..e85c4ad8 100644 --- a/examples/sqlite/src/entities/film_actor.rs +++ b/examples/sqlite/src/entities/film_actor.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -45,3 +45,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::actor::Entity")] + Actor, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/sqlite/src/entities/film_category.rs b/examples/sqlite/src/entities/film_category.rs index 1cc94c7b..8c63d97e 100644 --- a/examples/sqlite/src/entities/film_category.rs +++ b/examples/sqlite/src/entities/film_category.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -45,3 +45,11 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::category::Entity")] + Category, + #[sea_orm(entity = "super::film::Entity")] + Film, +} diff --git a/examples/sqlite/src/entities/film_text.rs b/examples/sqlite/src/entities/film_text.rs index b822b0fb..f5059f1e 100644 --- a/examples/sqlite/src/entities/film_text.rs +++ b/examples/sqlite/src/entities/film_text.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -15,3 +15,6 @@ pub struct Model { pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity {} diff --git a/examples/sqlite/src/entities/inventory.rs b/examples/sqlite/src/entities/inventory.rs index 48494f91..ec1bd955 100644 --- a/examples/sqlite/src/entities/inventory.rs +++ b/examples/sqlite/src/entities/inventory.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -53,3 +53,13 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::film::Entity")] + Film, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::store::Entity")] + Store, +} diff --git a/examples/sqlite/src/entities/language.rs b/examples/sqlite/src/entities/language.rs index d6538f96..b6d0913a 100644 --- a/examples/sqlite/src/entities/language.rs +++ b/examples/sqlite/src/entities/language.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -7,6 +7,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub language_id: i16, + #[sea_orm(column_type = "Binary(BlobSize::Blob(None))")] pub name: Vec, pub last_update: DateTimeUtc, } @@ -15,3 +16,6 @@ pub struct Model { pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity {} diff --git a/examples/sqlite/src/entities/mod.rs b/examples/sqlite/src/entities/mod.rs index a2976910..d767dff7 100644 --- a/examples/sqlite/src/entities/mod.rs +++ b/examples/sqlite/src/entities/mod.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 pub mod prelude; diff --git a/examples/sqlite/src/entities/payment.rs b/examples/sqlite/src/entities/payment.rs index 7e1edfec..11491465 100644 --- a/examples/sqlite/src/entities/payment.rs +++ b/examples/sqlite/src/entities/payment.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -63,3 +63,13 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/sqlite/src/entities/prelude.rs b/examples/sqlite/src/entities/prelude.rs index 8c1f2aac..3b2c48d9 100644 --- a/examples/sqlite/src/entities/prelude.rs +++ b/examples/sqlite/src/entities/prelude.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 pub use super::actor::Entity as Actor; pub use super::address::Entity as Address; diff --git a/examples/sqlite/src/entities/rental.rs b/examples/sqlite/src/entities/rental.rs index 7e29307e..41ee73e5 100644 --- a/examples/sqlite/src/entities/rental.rs +++ b/examples/sqlite/src/entities/rental.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -70,3 +70,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/sqlite/src/entities/staff.rs b/examples/sqlite/src/entities/staff.rs index c02cae2a..9ee040a5 100644 --- a/examples/sqlite/src/entities/staff.rs +++ b/examples/sqlite/src/entities/staff.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -11,6 +11,7 @@ pub struct Model { pub last_name: String, pub address_id: i32, pub reports_to_id: Option, + #[sea_orm(column_type = "Binary(BlobSize::Blob(None))", nullable)] pub picture: Option>, pub email: Option, pub store_id: i32, @@ -77,3 +78,19 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::payment::Entity")] + Payment, + #[sea_orm(entity = "super::rental::Entity")] + Rental, + #[sea_orm(entity = "Entity", def = "Relation::SelfRef.def()")] + SelfRef, + #[sea_orm(entity = "super::store::Entity")] + Store, + #[sea_orm(entity = "Entity", def = "Relation::SelfRef.def().rev()")] + SelfRefReverse, +} diff --git a/examples/sqlite/src/entities/store.rs b/examples/sqlite/src/entities/store.rs index 6b2b36d6..af08a36a 100644 --- a/examples/sqlite/src/entities/store.rs +++ b/examples/sqlite/src/entities/store.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -61,3 +61,15 @@ impl Related for Entity { } impl ActiveModelBehavior for ActiveModel {} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)] +pub enum RelatedEntity { + #[sea_orm(entity = "super::address::Entity")] + Address, + #[sea_orm(entity = "super::customer::Entity")] + Customer, + #[sea_orm(entity = "super::inventory::Entity")] + Inventory, + #[sea_orm(entity = "super::staff::Entity")] + Staff, +} diff --git a/examples/sqlite/src/main.rs b/examples/sqlite/src/main.rs index c6052c08..7fcfd733 100644 --- a/examples/sqlite/src/main.rs +++ b/examples/sqlite/src/main.rs @@ -26,7 +26,7 @@ lazy_static! { #[handler] async fn graphql_playground() -> impl IntoResponse { - Html(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT))) + Html(playground_source(GraphQLPlaygroundConfig::new(&ENDPOINT))) } #[tokio::main] diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index 185c390c..b3b77bf1 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -1,9 +1,7 @@ -use crate::OrmDataloader; +use crate::{entities::*, OrmDataloader}; use async_graphql::{dataloader::DataLoader, dynamic::*}; -use sea_orm::{DatabaseConnection, RelationTrait}; -use seaography::{ - Builder, BuilderContext, EntityObjectRelationBuilder, EntityObjectViaRelationBuilder, -}; +use sea_orm::DatabaseConnection; +use seaography::{Builder, BuilderContext}; lazy_static::lazy_static! { static ref CONTEXT : BuilderContext = BuilderContext :: default () ; } @@ -14,229 +12,27 @@ pub fn schema( complexity: Option, ) -> Result { let mut builder = Builder::new(&CONTEXT); - let entity_object_relation_builder = EntityObjectRelationBuilder { context: &CONTEXT }; - let entity_object_via_relation_builder = EntityObjectViaRelationBuilder { context: &CONTEXT }; - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "actor", - crate::entities::film_actor::Relation::Actor.def(), - ), - entity_object_relation_builder - .get_relation::( - "film", - crate::entities::film_actor::Relation::Film.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::rental::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::rental::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::rental::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::rental::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::( - "film", - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::staff::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::staff::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::staff::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "selfRef", - crate::entities::staff::Relation::SelfRef.def(), - ), - entity_object_relation_builder - .get_relation::( - "selfRefReverse", - crate::entities::staff::Relation::SelfRef.def().rev(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::staff::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "city", - crate::entities::country::Relation::City.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::("actor"), - entity_object_via_relation_builder - .get_relation::( - "category", - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::film::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "language1", - crate::entities::film::Relation::Language1.def(), - ), - entity_object_relation_builder - .get_relation::( - "language2", - crate::entities::film::Relation::Language2.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_via_relation_builder - .get_relation::("film"), - ]); - builder.register_entity::(vec![]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::city::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "country", - crate::entities::city::Relation::Country.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "film", - crate::entities::inventory::Relation::Film.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::inventory::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::inventory::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![]); - builder . register_entity :: < crate :: entities :: film_category :: Entity > (vec ! [entity_object_relation_builder . get_relation :: < crate :: entities :: film_category :: Entity , crate :: entities :: category :: Entity > ("category" , crate :: entities :: film_category :: Relation :: Category . def ()) , entity_object_relation_builder . get_relation :: < crate :: entities :: film_category :: Entity , crate :: entities :: film :: Entity > ("film" , crate :: entities :: film_category :: Relation :: Film . def ())]) ; - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::customer::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "payment", - crate::entities::customer::Relation::Payment.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::customer::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::customer::Relation::Store.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "address", - crate::entities::store::Relation::Address.def(), - ), - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::store::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "inventory", - crate::entities::store::Relation::Inventory.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::store::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::payment::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "rental", - crate::entities::payment::Relation::Rental.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::payment::Relation::Staff.def(), - ), - ]); - builder.register_entity::(vec![ - entity_object_relation_builder - .get_relation::( - "city", - crate::entities::address::Relation::City.def(), - ), - entity_object_relation_builder - .get_relation::( - "customer", - crate::entities::address::Relation::Customer.def(), - ), - entity_object_relation_builder - .get_relation::( - "staff", - crate::entities::address::Relation::Staff.def(), - ), - entity_object_relation_builder - .get_relation::( - "store", - crate::entities::address::Relation::Store.def(), - ), - ]); + seaography::register_entities!( + builder, + [ + film_actor, + rental, + category, + staff, + country, + film, + actor, + language, + city, + inventory, + film_text, + film_category, + customer, + store, + payment, + address, + ] + ); let schema = builder.schema_builder(); let schema = if let Some(depth) = depth { schema.limit_depth(depth) diff --git a/examples/sqlite/tests/guard_tests.rs b/examples/sqlite/tests/guard_tests.rs index 6eed5132..f97886a4 100644 --- a/examples/sqlite/tests/guard_tests.rs +++ b/examples/sqlite/tests/guard_tests.rs @@ -287,10 +287,10 @@ pub async fn get_schema() -> Schema { } pub fn assert_eq(a: Response, b: &str) { - assert_eq!( - a.data.into_json().unwrap(), - serde_json::from_str::(b).unwrap() - ) + assert_eq!( + a.data.into_json().unwrap(), + serde_json::from_str::(b).unwrap() + ) } #[tokio::test] diff --git a/examples/sqlite/tests/query_tests.rs b/examples/sqlite/tests/query_tests.rs index 1725a4ba..cebcaeab 100644 --- a/examples/sqlite/tests/query_tests.rs +++ b/examples/sqlite/tests/query_tests.rs @@ -758,4 +758,3 @@ async fn related_queries_pagination() { "#, ) } - diff --git a/generator/Cargo.toml b/generator/Cargo.toml index 127efbb2..74844693 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -13,10 +13,10 @@ keywords = ["async", "graphql", "mysql", "postgres", "sqlite"] categories = ["database"] [dependencies] -quote = "1.0.23" -proc-macro2 = "1.0.51" -syn = { version = "1.0.109", features = ["full"] } +quote = "1.0.31" +proc-macro2 = "1.0.66" +syn = { version = "2.0.27", features = ["full"] } heck = "0.4.1" -itertools = "0.10.5" -sea-query = { version = "0.28.3", default-features = false } -thiserror = "1.0.38" \ No newline at end of file +itertools = "0.11.0" +sea-query = { version = "0.30.0", default-features = false } +thiserror = "1.0.44" \ No newline at end of file diff --git a/generator/src/parser.rs b/generator/src/parser.rs index 9fdfb0bc..f7458246 100644 --- a/generator/src/parser.rs +++ b/generator/src/parser.rs @@ -1,193 +1,19 @@ -use std::collections::BTreeMap; +use proc_macro2::Ident; +use quote::format_ident; -use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; - -use crate::writer::EntityDefinition; - -pub struct RelationDef { - pub target: TokenStream, - pub variant: TokenStream, - pub related: bool, - pub reverse: bool, - pub self_rel: bool, -} - -impl RelationDef { - fn related(target: TokenStream) -> Self { - Self { - target, - variant: quote! {}, - related: true, - reverse: false, - self_rel: false, - } - } +pub struct EntityDefinition { + pub name: Ident, } -pub fn parse_entity(file_name: String, file_content: String) -> EntityDefinition { +pub fn parse_entity(file_name: String) -> EntityDefinition { let name = &file_name[..file_name.len() - 3]; - let name: TokenStream = format!("crate::entities::{}", name).parse().unwrap(); - - let tree = syn::parse2::(file_content.parse().unwrap()).unwrap(); - - let relations: BTreeMap = - tree.items - .iter() - .fold(BTreeMap::new(), |mut acc, cur| match cur { - syn::Item::Impl(implementation) => { - if let Some((_bang, path, _for)) = &implementation.trait_ { - let path = path.to_token_stream().to_string(); - if path.starts_with("Related") { - let path: TokenStream = path[18..path.len() - 1].parse().unwrap(); - let path = quote! { crate::entities::#path }; - - let to_method = implementation - .items - .iter() - .find(|item| match item { - syn::ImplItem::Method(method) => method - .sig - .to_token_stream() - .to_string() - .starts_with("fn to ()"), - _ => false, - }) - .expect("We expect Related to have `to` method"); - - let via_method = implementation.items.iter().find(|item| match item { - syn::ImplItem::Method(method) => method - .sig - .to_token_stream() - .to_string() - .starts_with("fn via ()"), - _ => false, - }); - - let name: String = if let syn::ImplItem::Method(method) = to_method { - let ident = - (&method.block.stmts[0]).into_token_stream().to_string(); - let ident: String = ident - [12..ident.chars().position(|c| c == '.').unwrap() - 1] - .into(); - ident.split("::").last().unwrap().trim().into() - } else { - panic!("We expect to_method variable to be Method type") - }; - - if let Some(_) = via_method { - acc.insert(name, RelationDef::related(path)); - } - } - } - acc - } - syn::Item::Enum(enumeration) => { - if enumeration.ident.to_string().eq("Relation") { - enumeration.variants.iter().for_each(|variant| { - let name = variant.ident.to_string(); - let attr = variant.attrs.iter().find(|attr| { - attr.path - .get_ident() - .map(|i| i.to_string().eq("sea_orm")) - .unwrap_or_else(|| false) - }); - if let Some(attr) = attr { - let ident = quote::format_ident!("{}", name); - - let attributes_string = attr.tokens.to_string(); - let attributes_string = - &attributes_string[1..attributes_string.len() - 1]; - - let attributes = attributes_string.split(",").fold( - std::collections::BTreeMap::<&str, &str>::new(), - |mut acc, cur| { - let mut parts = cur.split("="); - if parts.clone().count() == 2 { - let key = parts - .next() - .expect("We expect to have first part") - .trim(); - let value = parts - .next() - .expect("We expect to have second part") - .trim(); - acc.insert(key, value); - } - - acc - }, - ); - - let belongs_to = attributes.get("belongs_to"); - let has_one = attributes.get("has_one"); - let has_many = attributes.get("has_many"); - - let target = if let Some(v) = belongs_to { - v - } else if let Some(v) = has_one { - v - } else if let Some(v) = has_many { - v - } else { - panic!("Invalid relation definition") - }; - - let target = target.replace("super", "crate::entities"); - - let target: TokenStream = - target[1..target.len() - 1].parse().unwrap(); - - let self_belongs_to = - belongs_to.map_or_else(|| false, |v| v.eq(&"\"Entity\"")); - let self_has_one = - has_one.map_or_else(|| false, |v| v.eq(&"\"Entity\"")); - let self_has_many = - has_many.map_or_else(|| false, |v| v.eq(&"\"Entity\"")); - - if self_belongs_to || self_has_one || self_has_many { - let normal = RelationDef { - target: target.clone(), - variant: quote! { #ident }, - related: false, - reverse: false, - self_rel: true, - }; - acc.insert(name.clone(), normal); - - let reverse = RelationDef { - target, - variant: quote! { #ident }, - related: false, - reverse: true, - self_rel: true, - }; - acc.insert(format!("{}Reverse", name), reverse); - } else { - let normal = RelationDef { - target, - variant: quote! { #ident }, - related: false, - reverse: false, - self_rel: false, - }; - acc.insert(name, normal); - } - } - }); - acc - } else { - acc - } - } - _ => acc, - }); + let name = format_ident!("{}", name); - EntityDefinition { name, relations } + EntityDefinition { name } } pub struct EnumerationDefinition { - pub name: TokenStream, + pub name: Ident, } pub fn parse_enumerations(file_content: String) -> Vec { @@ -202,7 +28,7 @@ pub fn parse_enumerations(file_content: String) -> Vec { }) .map(|item| match item { syn::Item::Enum(enumeration) => EnumerationDefinition { - name: enumeration.ident.to_token_stream(), + name: enumeration.ident.clone(), }, _ => panic!("This is unreachable."), }) diff --git a/generator/src/templates/actix_cargo.toml b/generator/src/templates/actix_cargo.toml index 09d39831..7b8324f7 100644 --- a/generator/src/templates/actix_cargo.toml +++ b/generator/src/templates/actix_cargo.toml @@ -5,14 +5,14 @@ version = "0.3.0" [dependencies] actix-web = { version = "4.3.1", default-features = false, features = ["macros"] } -async-graphql-actix-web = { version = "5.0.6" } -async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -async-trait = { version = "0.1.64" } +async-graphql-actix-web = { version = "5.0.10" } +async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } +async-trait = { version = "0.1.72" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["", "runtime-async-std-native-tls"] } -tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } +sea-orm = { version = "0.12.0-rc.5", features = ["", "runtime-async-std-native-tls", "seaography"] } +tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } -tracing-subscriber = { version = "0.3.16" } +tracing-subscriber = { version = "0.3.17" } lazy_static = { version = "1.4.0" } [dependencies.seaography] @@ -20,7 +20,7 @@ version = "" # seaography version features = ["with-decimal", "with-chrono"] [dev-dependencies] -serde_json = { version = "1.0.82" } +serde_json = { version = "1.0.103" } [workspace] members = [] \ No newline at end of file diff --git a/generator/src/templates/poem.rs b/generator/src/templates/poem.rs index 2ad1857c..3a0e57c3 100644 --- a/generator/src/templates/poem.rs +++ b/generator/src/templates/poem.rs @@ -38,7 +38,7 @@ pub fn generate_main(crate_name: &str) -> TokenStream { #[handler] async fn graphql_playground() -> impl IntoResponse { - Html(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT))) + Html(playground_source(GraphQLPlaygroundConfig::new(&ENDPOINT))) } #[tokio::main] diff --git a/generator/src/templates/poem_cargo.toml b/generator/src/templates/poem_cargo.toml index 0c5c38fa..8e74f96a 100644 --- a/generator/src/templates/poem_cargo.toml +++ b/generator/src/templates/poem_cargo.toml @@ -4,15 +4,15 @@ name = "" version = "0.3.0" [dependencies] -poem = { version = "1.3.55" } -async-graphql-poem = { version = "5.0.6" } -async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -async-trait = { version = "0.1.64" } +poem = { version = "1.3.56" } +async-graphql-poem = { version = "5.0.10" } +async-graphql = { version = "5.0.10", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } +async-trait = { version = "0.1.72" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["", "runtime-async-std-native-tls"] } -tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } +sea-orm = { version = "0.12.0-rc.5", features = ["", "runtime-async-std-native-tls", "seaography"] } +tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } -tracing-subscriber = { version = "0.3.16" } +tracing-subscriber = { version = "0.3.17" } lazy_static = { version = "1.4.0" } [dependencies.seaography] @@ -20,7 +20,7 @@ version = "" # seaography version features = ["with-decimal", "with-chrono"] [dev-dependencies] -serde_json = { version = "1.0.82" } +serde_json = { version = "1.0.103" } [workspace] members = [] \ No newline at end of file diff --git a/generator/src/writer.rs b/generator/src/writer.rs index 8a066321..785496d5 100644 --- a/generator/src/writer.rs +++ b/generator/src/writer.rs @@ -1,21 +1,14 @@ -use std::collections::BTreeMap; use std::path::Path; -use heck::ToLowerCamelCase; use proc_macro2::TokenStream; use quote::quote; use crate::{ - parser::{parse_entity, parse_enumerations, RelationDef}, + parser::{parse_entity, parse_enumerations, EntityDefinition}, util::add_line_break, WebFrameworkEnum, }; -pub struct EntityDefinition { - pub name: TokenStream, - pub relations: BTreeMap, -} - pub fn generate_query_root>(entities_path: &P) -> TokenStream { let entities_paths = std::fs::read_dir(entities_path) .unwrap() @@ -38,49 +31,20 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { let entities: Vec = entities_paths .map(|path| { let file_name = path.file_name().unwrap().to_str().unwrap(); - let file_content = - std::fs::read_to_string(entities_path.as_ref().join(file_name)).unwrap(); - parse_entity(file_name.into(), file_content) + parse_entity(file_name.into()) }) .collect(); - let entities: Vec = entities.iter().map(|entity| { - let entity_path = &entity.name; - - let relations: Vec = entity.relations.iter().map(|(relationship_name, rel_def)| { - let variant = &rel_def.variant; - let target = &rel_def.target; - let relationship_name = relationship_name.to_lower_camel_case(); - - if rel_def.self_rel && rel_def.reverse { - quote!{ - entity_object_relation_builder.get_relation::<#entity_path::Entity, #entity_path::Entity>(#relationship_name, #entity_path::Relation::#variant.def().rev()) - } - } else if rel_def.related { - quote!{ - entity_object_via_relation_builder.get_relation::<#entity_path::Entity, #target>(#relationship_name) - } - } else if rel_def.self_rel { - quote!{ - entity_object_relation_builder.get_relation::<#entity_path::Entity, #entity_path::Entity>(#relationship_name, #entity_path::Relation::#variant.def()) - } - } else if rel_def.reverse { - quote!{ - entity_object_relation_builder.get_relation::<#target, #entity_path::Entity>(#relationship_name, #entity_path::Relation::#variant.def().rev()) - } - } else { - quote!{ - entity_object_relation_builder.get_relation::<#entity_path::Entity, #target>(#relationship_name, #entity_path::Relation::#variant.def()) - } - } - }).collect(); - - quote!{ - - builder.register_entity::<#entity_path::Entity>(vec![#(#relations),*]); + let entities: Vec = entities + .iter() + .map(|entity| { + let entity_path = &entity.name; - } - }).collect(); + quote! { + #entity_path + } + }) + .collect(); let enumerations = std::fs::read_dir(entities_path) .unwrap() @@ -112,19 +76,15 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { let name = &definition.name; quote! { - builder.register_enumeration::(); - } }); quote! { - use crate::OrmDataloader; + use crate::{entities::*, OrmDataloader}; use async_graphql::{dataloader::DataLoader, dynamic::*}; - use sea_orm::{DatabaseConnection, RelationTrait}; - use seaography::{ - Builder, BuilderContext, EntityObjectRelationBuilder, EntityObjectViaRelationBuilder, - }; + use sea_orm::DatabaseConnection; + use seaography::{Builder, BuilderContext}; lazy_static::lazy_static! { static ref CONTEXT: BuilderContext = BuilderContext::default(); @@ -137,10 +97,13 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { complexity: Option, ) -> Result { let mut builder = Builder::new(&CONTEXT); - let entity_object_relation_builder = EntityObjectRelationBuilder { context: &CONTEXT }; - let entity_object_via_relation_builder = EntityObjectViaRelationBuilder { context: &CONTEXT }; - #(#entities)* + seaography::register_entities!( + builder, + [ + #(#entities,)* + ] + ); #(#enumerations)* diff --git a/src/builder.rs b/src/builder.rs index ecc69162..c089da0a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -235,3 +235,42 @@ impl Builder { .register(query) } } + +pub trait RelationBuilder { + fn get_relation( + &self, + context: &'static crate::BuilderContext, + ) -> async_graphql::dynamic::Field; +} + +#[macro_export] +macro_rules! register_entity { + ($builder:expr, $module_path:ident) => { + $builder.register_entity::<$module_path::Entity>( + <$module_path::RelatedEntity as sea_orm::Iterable>::iter() + .map(|rel| seaography::RelationBuilder::get_relation(&rel, $builder.context)) + .collect(), + ); + }; +} + +#[macro_export] +macro_rules! register_entities { + ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { + $(seaography::register_entity!($builder, $module_paths);)* + }; +} + +#[macro_export] +macro_rules! register_entity_without_relation { + ($builder:expr, $module_path:ident) => { + $builder.register_entity::<$module_path::Entity>(vec![]); + }; +} + +#[macro_export] +macro_rules! register_entities_without_relation { + ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { + $(seaography::register_entity_without_relation!($builder, $module_paths);)* + }; +} diff --git a/src/inputs/active_enum_filter_input.rs b/src/inputs/active_enum_filter_input.rs index 5fc2ed4a..9215eb80 100644 --- a/src/inputs/active_enum_filter_input.rs +++ b/src/inputs/active_enum_filter_input.rs @@ -1,6 +1,6 @@ use async_graphql::dynamic::{InputObject, InputValue, ObjectAccessor, TypeRef}; use heck::ToUpperCamelCase; -use sea_orm::{ActiveEnum, ColumnTrait, Condition, DynIden, Iden}; +use sea_orm::{sea_query::SeaRc, ActiveEnum, ColumnTrait, Condition, DynIden, Iden}; use crate::{ActiveEnumBuilder, BuilderContext}; @@ -68,7 +68,7 @@ impl ActiveEnumFilterInputBuilder { pub fn prepare_enumeration_condition( filter: &ObjectAccessor, column: T, - variants: &[std::sync::Arc], + variants: &[SeaRc], condition: Condition, ) -> Condition where diff --git a/src/query/entity_object_via_relation.rs b/src/query/entity_object_via_relation.rs index 6cddcdba..88ea0dd4 100644 --- a/src/query/entity_object_via_relation.rs +++ b/src/query/entity_object_via_relation.rs @@ -32,9 +32,10 @@ impl EntityObjectViaRelationBuilder { { let context: &'static BuilderContext = self.context; let to_relation_definition = >::to(); - let via_relation_definition = >::via().expect( - "We expect this function to be used with Related that has `via` method implemented!", - ); + let via_relation_definition = match >::via() { + Some(def) => def, + None => >::to(), + }; let entity_object_builder = EntityObjectBuilder { context }; let connection_object_builder = ConnectionObjectBuilder { context };