From d23f8a2355c0a498d4a2f62fc09473b86c2a685d Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Tue, 18 Apr 2023 11:13:47 +0300 Subject: [PATCH 01/20] Modify generation to slim query_root.rs * Add `RelationBuilder` trait * Use seaography flag on generation * Use DeriveRelatedEntity macro * Slim down parsing * Slim down code generation --- generator/src/parser.rs | 192 ++---------------------- generator/src/writer.rs | 55 +------ src/builder.rs | 20 +++ src/query/entity_object_via_relation.rs | 7 +- 4 files changed, 39 insertions(+), 235 deletions(-) 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/writer.rs b/generator/src/writer.rs index 8a066321..92afce0f 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,47 +31,15 @@ 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),*]); - + seaography::register_entity!(builder, &CONTEXT, #entity_path); } }).collect(); @@ -112,19 +73,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(); diff --git a/src/builder.rs b/src/builder.rs index ecc69162..01c20ea7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -235,3 +235,23 @@ 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, $context:expr, $module_path:ident) => { + { + use sea_orm::Iterable; + + $builder.register_entity::<$module_path::Entity>( + $module_path::RelatedEntity::iter() + .map(|rel| seaography::RelationBuilder::get_relation(&rel, $context)) + .collect() + ); + } + + }; +} 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 }; From 0ce7bfed1cdb3d9132ca37f7c654082bb4849d2a Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Tue, 18 Apr 2023 11:14:15 +0300 Subject: [PATCH 02/20] Update Sqlite example and Readme.md --- README.md | 6 +- examples/sqlite/src/entities/actor.rs | 21 +- examples/sqlite/src/entities/address.rs | 14 +- examples/sqlite/src/entities/category.rs | 21 +- examples/sqlite/src/entities/city.rs | 10 +- examples/sqlite/src/entities/country.rs | 8 +- examples/sqlite/src/entities/customer.rs | 14 +- examples/sqlite/src/entities/film.rs | 36 ++- examples/sqlite/src/entities/film_actor.rs | 10 +- examples/sqlite/src/entities/film_category.rs | 10 +- examples/sqlite/src/entities/film_text.rs | 5 +- examples/sqlite/src/entities/inventory.rs | 12 +- examples/sqlite/src/entities/language.rs | 6 +- examples/sqlite/src/entities/mod.rs | 2 +- examples/sqlite/src/entities/payment.rs | 12 +- examples/sqlite/src/entities/prelude.rs | 2 +- examples/sqlite/src/entities/rental.rs | 14 +- examples/sqlite/src/entities/staff.rs | 19 +- examples/sqlite/src/entities/store.rs | 14 +- examples/sqlite/src/query_root.rs | 249 ++---------------- 20 files changed, 234 insertions(+), 251 deletions(-) diff --git a/README.md b/README.md index 6622f522..10e6c6a7 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/examples/sqlite/src/entities/actor.rs b/examples/sqlite/src/entities/actor.rs index ff14665f..a1d3b00e 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 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..cdfc9e6b 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 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..dd3d4ef0 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 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..6d4b445a 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 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..b1d4c73d 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 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..2c82bcae 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 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..dbf9f4ea 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 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..2d97e3ec 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 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..246fc8c4 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 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..68904053 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 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..d8741dfc 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 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, +} \ No newline at end of file diff --git a/examples/sqlite/src/entities/language.rs b/examples/sqlite/src/entities/language.rs index d6538f96..5eebcaaf 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 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..e64a59d9 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 pub mod prelude; diff --git a/examples/sqlite/src/entities/payment.rs b/examples/sqlite/src/entities/payment.rs index 7e1edfec..9eff525d 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 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..e0d0943f 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 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..1610c23c 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 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..5d1ac66d 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 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..6472c991 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 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/query_root.rs b/examples/sqlite/src/query_root.rs index 185c390c..8c52dcf4 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,24 @@ 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_entity!(builder, &CONTEXT, film_actor); + seaography::register_entity!(builder, &CONTEXT, rental); + seaography::register_entity!(builder, &CONTEXT, category); + seaography::register_entity!(builder, &CONTEXT, staff); + seaography::register_entity!(builder, &CONTEXT, country); + seaography::register_entity!(builder, &CONTEXT, film); + seaography::register_entity!(builder, &CONTEXT, actor); + seaography::register_entity!(builder, &CONTEXT, language); + seaography::register_entity!(builder, &CONTEXT, city); + seaography::register_entity!(builder, &CONTEXT, inventory); + seaography::register_entity!(builder, &CONTEXT, film_text); + seaography::register_entity!(builder, &CONTEXT, film_category); + seaography::register_entity!(builder, &CONTEXT, customer); + seaography::register_entity!(builder, &CONTEXT, store); + seaography::register_entity!(builder, &CONTEXT, payment); + seaography::register_entity!(builder, &CONTEXT, address); + let schema = builder.schema_builder(); let schema = if let Some(depth) = depth { schema.limit_depth(depth) From ee7b46d6d4d91ca6f3b8193d8bd6d07b1938d8e2 Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Tue, 18 Apr 2023 11:25:24 +0300 Subject: [PATCH 03/20] Fix formatting and clippy --- examples/sqlite/src/entities/inventory.rs | 2 +- examples/sqlite/src/main.rs | 2 +- examples/sqlite/tests/guard_tests.rs | 8 +++---- examples/sqlite/tests/query_tests.rs | 1 - generator/src/templates/poem.rs | 2 +- generator/src/writer.rs | 15 +++++++------ src/builder.rs | 26 +++++++++++------------ 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/examples/sqlite/src/entities/inventory.rs b/examples/sqlite/src/entities/inventory.rs index d8741dfc..8ea54d15 100644 --- a/examples/sqlite/src/entities/inventory.rs +++ b/examples/sqlite/src/entities/inventory.rs @@ -62,4 +62,4 @@ pub enum RelatedEntity { Rental, #[sea_orm(entity = "super::store::Entity")] Store, -} \ No newline at end of file +} 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/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/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/writer.rs b/generator/src/writer.rs index 92afce0f..5a5cb710 100644 --- a/generator/src/writer.rs +++ b/generator/src/writer.rs @@ -35,13 +35,16 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { }) .collect(); - let entities: Vec = entities.iter().map(|entity| { - let entity_path = &entity.name; + let entities: Vec = entities + .iter() + .map(|entity| { + let entity_path = &entity.name; - quote!{ - seaography::register_entity!(builder, &CONTEXT, #entity_path); - } - }).collect(); + quote! { + seaography::register_entity!(builder, &CONTEXT, #entity_path); + } + }) + .collect(); let enumerations = std::fs::read_dir(entities_path) .unwrap() diff --git a/src/builder.rs b/src/builder.rs index 01c20ea7..19b3ce87 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -237,21 +237,21 @@ impl Builder { } pub trait RelationBuilder { - fn get_relation(&self, context: &'static crate::BuilderContext) -> async_graphql::dynamic::Field; + fn get_relation( + &self, + context: &'static crate::BuilderContext, + ) -> async_graphql::dynamic::Field; } #[macro_export] macro_rules! register_entity { - ($builder:expr, $context:expr, $module_path:ident) => { - { - use sea_orm::Iterable; - - $builder.register_entity::<$module_path::Entity>( - $module_path::RelatedEntity::iter() - .map(|rel| seaography::RelationBuilder::get_relation(&rel, $context)) - .collect() - ); - } - - }; + ($builder:expr, $context:expr, $module_path:ident) => {{ + use sea_orm::Iterable; + + $builder.register_entity::<$module_path::Entity>( + $module_path::RelatedEntity::iter() + .map(|rel| seaography::RelationBuilder::get_relation(&rel, $context)) + .collect(), + ); + }}; } From ad9d96523e3af96be99d689f1eefd7cd5f73860c Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Mon, 24 Apr 2023 19:57:34 +0300 Subject: [PATCH 04/20] Fix temporary Cargo.toml point to depended branch --- Cargo.toml | 2 +- examples/mysql/Cargo.toml | 2 +- examples/postgres/Cargo.toml | 2 +- examples/sqlite/Cargo.toml | 2 +- generator/src/templates/actix_cargo.toml | 2 +- generator/src/templates/poem_cargo.toml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f4b96ce..8dcbc20a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ categories = ["database"] [dependencies] async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -sea-orm = { version = "0.11.0", default-features = false } +sea-orm = { version = "0.12.0", default-features = false, git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator" } itertools = { version = "0.10.5" } heck = { version = "0.4.1" } diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml index 88a05fbd..bde7dee9 100644 --- a/examples/mysql/Cargo.toml +++ b/examples/mysql/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["sqlx-mysql", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-mysql", "runtime-async-std-native-tls"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/examples/postgres/Cargo.toml b/examples/postgres/Cargo.toml index 49f298e1..bacddd86 100644 --- a/examples/postgres/Cargo.toml +++ b/examples/postgres/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["sqlx-postgres", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-postgres", "runtime-async-std-native-tls"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 8e3098ef..28f35df0 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["sqlx-sqlite", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-sqlite", "runtime-async-std-native-tls"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/generator/src/templates/actix_cargo.toml b/generator/src/templates/actix_cargo.toml index 09d39831..667e1de2 100644 --- a/generator/src/templates/actix_cargo.toml +++ b/generator/src/templates/actix_cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/generator/src/templates/poem_cargo.toml b/generator/src/templates/poem_cargo.toml index 0c5c38fa..cc4f7235 100644 --- a/generator/src/templates/poem_cargo.toml +++ b/generator/src/templates/poem_cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.11.0", features = ["", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } From 28b7930c62efb55497cbf6739baccdf518d4157b Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Mon, 24 Apr 2023 20:16:02 +0300 Subject: [PATCH 05/20] Add seaography::register_entities macro It returns the seaography `Builder` --- examples/sqlite/src/query_root.rs | 41 +++++++++++++++++-------------- generator/src/writer.rs | 10 +++----- src/builder.rs | 13 ++++++++++ 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index 8c52dcf4..d149f542 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -11,25 +11,28 @@ pub fn schema( depth: Option, complexity: Option, ) -> Result { - let mut builder = Builder::new(&CONTEXT); - - seaography::register_entity!(builder, &CONTEXT, film_actor); - seaography::register_entity!(builder, &CONTEXT, rental); - seaography::register_entity!(builder, &CONTEXT, category); - seaography::register_entity!(builder, &CONTEXT, staff); - seaography::register_entity!(builder, &CONTEXT, country); - seaography::register_entity!(builder, &CONTEXT, film); - seaography::register_entity!(builder, &CONTEXT, actor); - seaography::register_entity!(builder, &CONTEXT, language); - seaography::register_entity!(builder, &CONTEXT, city); - seaography::register_entity!(builder, &CONTEXT, inventory); - seaography::register_entity!(builder, &CONTEXT, film_text); - seaography::register_entity!(builder, &CONTEXT, film_category); - seaography::register_entity!(builder, &CONTEXT, customer); - seaography::register_entity!(builder, &CONTEXT, store); - seaography::register_entity!(builder, &CONTEXT, payment); - seaography::register_entity!(builder, &CONTEXT, address); - + let builder = seaography::register_entities!( + Builder::new(&CONTEXT), + &CONTEXT, + [ + 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/generator/src/writer.rs b/generator/src/writer.rs index 5a5cb710..edc263ab 100644 --- a/generator/src/writer.rs +++ b/generator/src/writer.rs @@ -41,7 +41,7 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { let entity_path = &entity.name; quote! { - seaography::register_entity!(builder, &CONTEXT, #entity_path); + #entity_path } }) .collect(); @@ -96,11 +96,9 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { depth: Option, 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)* + let builder = seaography::register_entities!(Builder::new(&CONTEXT), &CONTEXT, [ + #(#entities,)* + ]); #(#enumerations)* diff --git a/src/builder.rs b/src/builder.rs index 19b3ce87..2f29179d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -255,3 +255,16 @@ macro_rules! register_entity { ); }}; } + +#[macro_export] +macro_rules! register_entities { + ($builder:expr, $context:expr, [$($module_paths:ident),+ $(,)?]) => {{ + { + let mut builder = $builder; + + $(seaography::register_entity!(builder, $context, $module_paths);)* + + builder + } + }}; +} From f23b1af2e89f61a8a5cd9d46aa5e4e26d07fb45d Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 17 May 2023 22:46:02 +0800 Subject: [PATCH 06/20] Register "related entity" / "entity" without relation --- examples/sqlite/src/query_root.rs | 2 +- generator/src/writer.rs | 2 +- src/builder.rs | 36 +++++++++++++++----------- src/inputs/active_enum_filter_input.rs | 4 +-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index d149f542..3e5278db 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -11,7 +11,7 @@ pub fn schema( depth: Option, complexity: Option, ) -> Result { - let builder = seaography::register_entities!( + let builder = seaography::register_related_entities!( Builder::new(&CONTEXT), &CONTEXT, [ diff --git a/generator/src/writer.rs b/generator/src/writer.rs index edc263ab..f99e0f12 100644 --- a/generator/src/writer.rs +++ b/generator/src/writer.rs @@ -96,7 +96,7 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { depth: Option, complexity: Option, ) -> Result { - let builder = seaography::register_entities!(Builder::new(&CONTEXT), &CONTEXT, [ + let builder = seaography::register_related_entities!(Builder::new(&CONTEXT), &CONTEXT, [ #(#entities,)* ]); diff --git a/src/builder.rs b/src/builder.rs index 2f29179d..b22e3892 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -244,27 +244,33 @@ pub trait RelationBuilder { } #[macro_export] -macro_rules! register_entity { - ($builder:expr, $context:expr, $module_path:ident) => {{ - use sea_orm::Iterable; - +macro_rules! register_related_entity { + ($builder:expr, $module_path:ident) => { $builder.register_entity::<$module_path::Entity>( - $module_path::RelatedEntity::iter() - .map(|rel| seaography::RelationBuilder::get_relation(&rel, $context)) + <$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, $context:expr, [$($module_paths:ident),+ $(,)?]) => {{ - { - let mut builder = $builder; +macro_rules! register_related_entities { + ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { + $(seaography::register_related_entity!($builder, $module_paths);)* + }; +} - $(seaography::register_entity!(builder, $context, $module_paths);)* +#[macro_export] +macro_rules! register_entity { + ($builder:expr, $module_path:ident) => { + $builder.register_entity::<$module_path::Entity>(vec![]); + }; +} - builder - } - }}; +#[macro_export] +macro_rules! register_entities { + ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { + $(seaography::register_entity!($builder, $module_paths);)* + }; } diff --git a/src/inputs/active_enum_filter_input.rs b/src/inputs/active_enum_filter_input.rs index 5fc2ed4a..7924024e 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::{ActiveEnum, ColumnTrait, Condition, DynIden, Iden, sea_query::SeaRc}; 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 From 9e21805141db2509d4f51a03bc7dc7a599aa4290 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 17:18:17 +0800 Subject: [PATCH 07/20] Rename `register_entity` macros --- Cargo.toml | 2 +- examples/sqlite/src/query_root.rs | 11 ++++++++--- generator/src/writer.rs | 11 ++++++++--- src/builder.rs | 12 ++++++------ src/inputs/active_enum_filter_input.rs | 2 +- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8dcbc20a..f0d6b7a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ categories = ["database"] [dependencies] async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -sea-orm = { version = "0.12.0", default-features = false, git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator" } +sea-orm = { version = "0.12.0", default-features = false, git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["seaography"] } itertools = { version = "0.10.5" } heck = { version = "0.4.1" } diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index 3e5278db..015bd95c 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -11,9 +11,10 @@ pub fn schema( depth: Option, complexity: Option, ) -> Result { - let builder = seaography::register_related_entities!( - Builder::new(&CONTEXT), - &CONTEXT, + let mut builder = Builder::new(&CONTEXT); + + seaography::register_entities!( + builder, [ film_actor, rental, @@ -33,16 +34,20 @@ pub fn schema( address, ] ); + let schema = builder.schema_builder(); + let schema = if let Some(depth) = depth { schema.limit_depth(depth) } else { schema }; + let schema = if let Some(complexity) = complexity { schema.limit_complexity(complexity) } else { schema }; + schema.data(database).data(orm_dataloader).finish() } diff --git a/generator/src/writer.rs b/generator/src/writer.rs index f99e0f12..785496d5 100644 --- a/generator/src/writer.rs +++ b/generator/src/writer.rs @@ -96,9 +96,14 @@ pub fn generate_query_root>(entities_path: &P) -> TokenStream { depth: Option, complexity: Option, ) -> Result { - let builder = seaography::register_related_entities!(Builder::new(&CONTEXT), &CONTEXT, [ - #(#entities,)* - ]); + let mut builder = Builder::new(&CONTEXT); + + seaography::register_entities!( + builder, + [ + #(#entities,)* + ] + ); #(#enumerations)* diff --git a/src/builder.rs b/src/builder.rs index b22e3892..c089da0a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -244,7 +244,7 @@ pub trait RelationBuilder { } #[macro_export] -macro_rules! register_related_entity { +macro_rules! register_entity { ($builder:expr, $module_path:ident) => { $builder.register_entity::<$module_path::Entity>( <$module_path::RelatedEntity as sea_orm::Iterable>::iter() @@ -255,22 +255,22 @@ macro_rules! register_related_entity { } #[macro_export] -macro_rules! register_related_entities { +macro_rules! register_entities { ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { - $(seaography::register_related_entity!($builder, $module_paths);)* + $(seaography::register_entity!($builder, $module_paths);)* }; } #[macro_export] -macro_rules! register_entity { +macro_rules! register_entity_without_relation { ($builder:expr, $module_path:ident) => { $builder.register_entity::<$module_path::Entity>(vec![]); }; } #[macro_export] -macro_rules! register_entities { +macro_rules! register_entities_without_relation { ($builder:expr, [$($module_paths:ident),+ $(,)?]) => { - $(seaography::register_entity!($builder, $module_paths);)* + $(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 7924024e..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, sea_query::SeaRc}; +use sea_orm::{sea_query::SeaRc, ActiveEnum, ColumnTrait, Condition, DynIden, Iden}; use crate::{ActiveEnumBuilder, BuilderContext}; From 9b4c63b06b4f5b37849debd1aefe85272f765e81 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 17:46:11 +0800 Subject: [PATCH 08/20] Fix CI --- examples/mysql/Cargo.toml | 2 +- examples/postgres/Cargo.toml | 2 +- examples/sqlite/Cargo.toml | 2 +- generator/src/templates/actix_cargo.toml | 2 +- generator/src/templates/poem_cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml index bde7dee9..7e1ae2cf 100644 --- a/examples/mysql/Cargo.toml +++ b/examples/mysql/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-mysql", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/examples/postgres/Cargo.toml b/examples/postgres/Cargo.toml index bacddd86..2033acca 100644 --- a/examples/postgres/Cargo.toml +++ b/examples/postgres/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-postgres", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 28f35df0..ff99e412 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-sqlite", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-sqlite", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/generator/src/templates/actix_cargo.toml b/generator/src/templates/actix_cargo.toml index 667e1de2..8a7ff296 100644 --- a/generator/src/templates/actix_cargo.toml +++ b/generator/src/templates/actix_cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/generator/src/templates/poem_cargo.toml b/generator/src/templates/poem_cargo.toml index cc4f7235..5058b36d 100644 --- a/generator/src/templates/poem_cargo.toml +++ b/generator/src/templates/poem_cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls"] } +sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } From 63a6edd267f4a8f421b75c75b0f4e27ab2cdafed Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 18:07:54 +0800 Subject: [PATCH 09/20] Update docs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 10e6c6a7..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 -seaography +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 -seaography +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 -seaography +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 ``` From bd91d1e4d5010a4c47ba7bcf8280d1485745027b Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 18:20:05 +0800 Subject: [PATCH 10/20] Update SQLite example --- examples/sqlite/src/query_root.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index 015bd95c..497efdad 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -12,42 +12,37 @@ pub fn schema( complexity: Option, ) -> Result { let mut builder = Builder::new(&CONTEXT); - seaography::register_entities!( builder, [ - film_actor, rental, - category, + film_actor, staff, - country, + address, + store, film, - actor, - language, city, + payment, inventory, + category, + actor, + customer, + language, film_text, film_category, - customer, - store, - payment, - address, + country, ] ); - let schema = builder.schema_builder(); - let schema = if let Some(depth) = depth { schema.limit_depth(depth) } else { schema }; - let schema = if let Some(complexity) = complexity { schema.limit_complexity(complexity) } else { schema }; - schema.data(database).data(orm_dataloader).finish() } From 8ab9001d13442eb8b1a0c03dbd691dd7508108a3 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 20:27:48 +0800 Subject: [PATCH 11/20] Update Postgres example --- examples/postgres/src/entities/actor.rs | 21 +- examples/postgres/src/entities/address.rs | 14 +- examples/postgres/src/entities/category.rs | 21 +- examples/postgres/src/entities/city.rs | 10 +- examples/postgres/src/entities/country.rs | 8 +- examples/postgres/src/entities/customer.rs | 14 +- examples/postgres/src/entities/film.rs | 42 ++- examples/postgres/src/entities/film_actor.rs | 10 +- .../postgres/src/entities/film_category.rs | 10 +- examples/postgres/src/entities/inventory.rs | 12 +- examples/postgres/src/entities/language.rs | 5 +- examples/postgres/src/entities/mod.rs | 2 +- examples/postgres/src/entities/payment.rs | 12 +- examples/postgres/src/entities/prelude.rs | 2 +- examples/postgres/src/entities/rental.rs | 14 +- .../src/entities/sea_orm_active_enums.rs | 2 +- examples/postgres/src/entities/staff.rs | 15 +- examples/postgres/src/entities/store.rs | 14 +- examples/postgres/src/main.rs | 2 +- examples/postgres/src/query_root.rs | 240 ++---------------- 20 files changed, 229 insertions(+), 241 deletions(-) diff --git a/examples/postgres/src/entities/actor.rs b/examples/postgres/src/entities/actor.rs index ed2d47ad..4e06075c 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 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..9fe493b3 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 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..82bbc533 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 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..335ce59b 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 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..215460ba 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 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..97b14eb6 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 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..c8d939f0 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 use super::sea_orm_active_enums::MpaaRating; use sea_orm::entity::prelude::*; @@ -22,13 +22,17 @@ 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>, + #[sea_orm(column_type = "custom(\"tsvector\")")] + pub fulltext: String, } #[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 +53,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 +90,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..4472d37f 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 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..7b6fc87a 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 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..56b54576 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 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..471b6b8a 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 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..d6603858 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 pub mod prelude; diff --git a/examples/postgres/src/entities/payment.rs b/examples/postgres/src/entities/payment.rs index a590c444..d893f4a1 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 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..cc16fc4b 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 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..65e5d566 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 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..61bcab20 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 use sea_orm::entity::prelude::*; diff --git a/examples/postgres/src/entities/staff.rs b/examples/postgres/src/entities/staff.rs index 3f61badf..d45df645 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 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..d8d2ab6f 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 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..71e6d468 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, + [ + rental, + film_actor, + staff, + address, + store, + film, + city, + payment, + inventory, + category, + actor, + customer, + language, + film_category, + country, + ] + ); builder.register_enumeration::(); let schema = builder.schema_builder(); let schema = if let Some(depth) = depth { From 6fc83a31b81823e3a17e7ffe6148866b43f41643 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 20:36:41 +0800 Subject: [PATCH 12/20] Update MySQL example --- examples/mysql/src/entities/actor.rs | 23 +- examples/mysql/src/entities/address.rs | 21 +- examples/mysql/src/entities/category.rs | 21 +- examples/mysql/src/entities/city.rs | 14 +- examples/mysql/src/entities/country.rs | 10 +- examples/mysql/src/entities/customer.rs | 22 +- examples/mysql/src/entities/film.rs | 49 +++- examples/mysql/src/entities/film_actor.rs | 14 +- examples/mysql/src/entities/film_category.rs | 12 +- examples/mysql/src/entities/film_text.rs | 5 +- examples/mysql/src/entities/inventory.rs | 20 +- examples/mysql/src/entities/language.rs | 7 +- examples/mysql/src/entities/mod.rs | 2 +- examples/mysql/src/entities/payment.rs | 20 +- examples/mysql/src/entities/prelude.rs | 2 +- examples/mysql/src/entities/rental.rs | 21 +- .../src/entities/sea_orm_active_enums.rs | 2 +- examples/mysql/src/entities/staff.rs | 30 ++- examples/mysql/src/entities/store.rs | 20 +- examples/mysql/src/main.rs | 2 +- examples/mysql/src/query_root.rs | 252 ++---------------- examples/mysql/tests/query_tests.rs | 2 +- 22 files changed, 273 insertions(+), 298 deletions(-) diff --git a/examples/mysql/src/entities/actor.rs b/examples/mysql/src/entities/actor.rs index ff14665f..e528469a 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 use sea_orm::entity::prelude::*; @@ -6,14 +6,23 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "actor")] pub struct Model { #[sea_orm(primary_key)] - pub actor_id: i32, + pub actor_id: u16, pub first_name: String, pub last_name: String, pub last_update: DateTimeUtc, } #[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..e089d953 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 use sea_orm::entity::prelude::*; @@ -6,14 +6,15 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "address")] pub struct Model { #[sea_orm(primary_key)] - pub address_id: i32, + pub address_id: u16, pub address: String, pub address2: Option, pub district: String, - pub city_id: i32, + pub city_id: u16, pub postal_code: Option, pub phone: String, - pub location: Option>, + #[sea_orm(column_type = "custom(\"GEOMETRY\")")] + pub location: String, 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..8666f3a9 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 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..338fd16b 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 use sea_orm::entity::prelude::*; @@ -6,9 +6,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "city")] pub struct Model { #[sea_orm(primary_key)] - pub city_id: i32, + pub city_id: u16, pub city: String, - pub country_id: i32, + pub country_id: u16, pub last_update: DateTimeUtc, } @@ -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..94bf515b 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 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "country")] pub struct Model { #[sea_orm(primary_key)] - pub country_id: i32, + pub country_id: u16, pub country: String, pub last_update: DateTimeUtc, } @@ -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..42ef5be4 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 use sea_orm::entity::prelude::*; @@ -6,15 +6,15 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "customer")] pub struct Model { #[sea_orm(primary_key)] - pub customer_id: i32, - pub store_id: i32, + pub customer_id: u16, + pub store_id: u8, pub first_name: String, pub last_name: String, pub email: Option, - pub address_id: i32, + pub address_id: u16, pub active: i8, pub create_date: DateTime, - pub last_update: DateTimeUtc, + pub last_update: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -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..73afd2fb 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 use super::sea_orm_active_enums::Rating; use sea_orm::entity::prelude::*; @@ -7,17 +7,18 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "film")] pub struct Model { #[sea_orm(primary_key)] - pub film_id: i32, + pub film_id: u16, pub title: String, #[sea_orm(column_type = "Text", nullable)] pub description: Option, - pub release_year: Option, - pub language_id: i32, - pub original_language_id: Option, - pub rental_duration: i32, + #[sea_orm(column_type = "Text", nullable)] + pub release_year: Option, + pub language_id: u8, + pub original_language_id: Option, + pub rental_duration: u8, #[sea_orm(column_type = "Decimal(Some((4, 2)))")] pub rental_rate: Decimal, - pub length: Option, + pub length: Option, #[sea_orm(column_type = "Decimal(Some((5, 2)))")] pub replacement_cost: Decimal, pub rating: Option, @@ -31,6 +32,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 +56,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 +93,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..18bed4e3 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 use sea_orm::entity::prelude::*; @@ -6,9 +6,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "film_actor")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub actor_id: i32, + pub actor_id: u16, #[sea_orm(primary_key, auto_increment = false)] - pub film_id: i32, + pub film_id: u16, pub last_update: DateTimeUtc, } @@ -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..be619a7e 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 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "film_category")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub film_id: i32, + pub film_id: u16, #[sea_orm(primary_key, auto_increment = false)] pub category_id: u8, pub last_update: DateTimeUtc, @@ -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..6949e8f0 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 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..c6dd75c9 100644 --- a/examples/mysql/src/entities/inventory.rs +++ b/examples/mysql/src/entities/inventory.rs @@ -1,14 +1,14 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0 use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "inventory")] pub struct Model { - #[sea_orm(primary_key)] - pub inventory_id: i32, - pub film_id: i32, - pub store_id: i32, + #[sea_orm(primary_key, column_type = "custom(\"MEDIUMINT UNSIGNED\")")] + pub inventory_id: String, + pub film_id: u16, + pub store_id: u8, pub last_update: DateTimeUtc, } @@ -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..be7b55b1 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 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "language")] pub struct Model { #[sea_orm(primary_key)] - pub language_id: i32, + pub language_id: u8, pub name: String, pub last_update: DateTimeUtc, } @@ -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..2fe6c0aa 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 pub mod prelude; diff --git a/examples/mysql/src/entities/payment.rs b/examples/mysql/src/entities/payment.rs index 638f488a..40d0042e 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 use sea_orm::entity::prelude::*; @@ -6,14 +6,14 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "payment")] pub struct Model { #[sea_orm(primary_key)] - pub payment_id: i32, - pub customer_id: i32, - pub staff_id: i32, + pub payment_id: u16, + pub customer_id: u16, + pub staff_id: u8, pub rental_id: Option, #[sea_orm(column_type = "Decimal(Some((5, 2)))")] pub amount: Decimal, pub payment_date: DateTime, - pub last_update: DateTimeUtc, + pub last_update: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -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..e0d0943f 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 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..37c4a549 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 use sea_orm::entity::prelude::*; @@ -8,10 +8,11 @@ pub struct Model { #[sea_orm(primary_key)] pub rental_id: i32, pub rental_date: DateTime, - pub inventory_id: i32, - pub customer_id: i32, + #[sea_orm(column_type = "custom(\"MEDIUMINT UNSIGNED\")")] + pub inventory_id: String, + pub customer_id: u16, pub return_date: Option, - pub staff_id: i32, + pub staff_id: u8, pub last_update: DateTimeUtc, } @@ -70,3 +71,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..d0400bd8 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 use sea_orm::entity::prelude::*; diff --git a/examples/mysql/src/entities/staff.rs b/examples/mysql/src/entities/staff.rs index 73572f09..7127da6e 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 use sea_orm::entity::prelude::*; @@ -6,14 +6,14 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "staff")] pub struct Model { #[sea_orm(primary_key)] - pub staff_id: i32, + pub staff_id: u8, pub first_name: String, pub last_name: String, - pub address_id: i32, - pub reports_to_id: Option, + pub address_id: u16, + #[sea_orm(column_type = "Binary(BlobSize::Blob(None))", nullable)] pub picture: Option>, pub email: Option, - pub store_id: i32, + pub store_id: u8, pub active: i8, pub username: String, pub password: Option, @@ -34,14 +34,6 @@ pub enum Relation { Payment, #[sea_orm(has_many = "super::rental::Entity")] Rental, - #[sea_orm( - belongs_to = "Entity", - from = "Column::ReportsToId", - to = "Column::StaffId", - on_update = "Cascade", - on_delete = "Restrict" - )] - SelfRef, #[sea_orm( belongs_to = "super::store::Entity", from = "Column::StoreId", @@ -77,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/mysql/src/entities/store.rs b/examples/mysql/src/entities/store.rs index abd0007e..effa6334 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 use sea_orm::entity::prelude::*; @@ -6,10 +6,10 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "store")] pub struct Model { #[sea_orm(primary_key)] - pub store_id: i32, + pub store_id: u8, #[sea_orm(unique)] - pub manager_staff_id: i32, - pub address_id: i32, + pub manager_staff_id: u8, + pub address_id: u16, pub last_update: DateTimeUtc, } @@ -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..1f8a9cec 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, + [ + rental, + film_actor, + staff, + address, + store, + film, + city, + payment, + inventory, + category, + actor, + customer, + language, + film_text, + film_category, + country, + ] + ); builder.register_enumeration::(); let schema = builder.schema_builder(); let schema = if let Some(depth) = depth { diff --git a/examples/mysql/tests/query_tests.rs b/examples/mysql/tests/query_tests.rs index d19fc994..67752765 100644 --- a/examples/mysql/tests/query_tests.rs +++ b/examples/mysql/tests/query_tests.rs @@ -3,7 +3,7 @@ use sea_orm::Database; use seaography_mysql_example::OrmDataloader; pub async fn get_schema() -> Schema { - let database = Database::connect("mysql://sea:sea@127.0.0.1/sakila") + let database = Database::connect("mysql://root:root@127.0.0.1/sakila") .await .unwrap(); let orm_dataloader: DataLoader = DataLoader::new( From f1028740682c03bc90eb7fe569c85c25b2225b6a Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 18 May 2023 20:39:26 +0800 Subject: [PATCH 13/20] Temporary suspended generate entity and seaography code from scratch --- .github/workflows/tests.yaml | 148 +++++++++++++++++------------------ 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0f3a137c..72bf05ed 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -91,26 +91,26 @@ jobs: profile: minimal toolchain: stable override: true - - name: Install sea-orm-cli - uses: baptiste0928/cargo-install@v2 - with: - crate: sea-orm-cli - version: '0.11.0' - - name: Remove generated folder - run: rm -rf ./examples/sqlite/src + # - name: Install sea-orm-cli + # uses: baptiste0928/cargo-install@v2 + # with: + # crate: sea-orm-cli + # version: '0.11.0' + # - 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 - - name: Generate Seaography project - uses: actions-rs/cargo@v1 - with: - command: run - args: > - --package seaography-cli -- - ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f poem - - name: Depends on local seaography - run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml + # - name: Generate entities + # run: sea-orm-cli generate entity -o examples/sqlite/src/entities -u sqlite://sakila.db + # - name: Generate Seaography project + # uses: actions-rs/cargo@v1 + # with: + # command: run + # args: > + # --package seaography-cli -- + # ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f poem + # - name: Depends on local seaography + # run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml - name: Build example working-directory: ./examples/sqlite run: cargo build @@ -131,26 +131,26 @@ jobs: profile: minimal toolchain: stable override: true - - name: Install sea-orm-cli - uses: baptiste0928/cargo-install@v2 - with: - crate: sea-orm-cli - version: '0.11.0' - - name: Remove generated folder - run: rm -rf ./examples/sqlite/src + # - name: Install sea-orm-cli + # uses: baptiste0928/cargo-install@v2 + # with: + # crate: sea-orm-cli + # version: '0.11.0' + # - 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 - - name: Generate Seaography project - uses: actions-rs/cargo@v1 - with: - command: run - args: > - --package seaography-cli -- - ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f actix - - name: Depends on local seaography - run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml + # - name: Generate entities + # run: sea-orm-cli generate entity -o examples/sqlite/src/entities -u sqlite://sakila.db + # - name: Generate Seaography project + # uses: actions-rs/cargo@v1 + # with: + # command: run + # args: > + # --package seaography-cli -- + # ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f actix + # - name: Depends on local seaography + # run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml - name: Build example working-directory: ./examples/sqlite run: cargo build @@ -186,13 +186,13 @@ jobs: profile: minimal toolchain: stable override: true - - name: Install sea-orm-cli - uses: baptiste0928/cargo-install@v2 - with: - crate: sea-orm-cli - version: '0.11.0' - - name: Remove generated folder - run: rm -rf ./examples/mysql/src + # - name: Install sea-orm-cli + # uses: baptiste0928/cargo-install@v2 + # with: + # crate: sea-orm-cli + # version: '0.11.0' + # - name: Remove generated folder + # run: rm -rf ./examples/mysql/src - name: Create DB run: mysql -uroot -h 127.0.0.1 mysql -e 'CREATE DATABASE `sakila`' - name: Grant Privilege @@ -203,17 +203,17 @@ jobs: - name: Import DB Data 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 - - name: Generate Seaography project - uses: actions-rs/cargo@v1 - with: - command: run - args: > - --package seaography-cli -- - ./examples/mysql ./examples/mysql/src/entities mysql://sea:sea@127.0.0.1/sakila seaography-mysql-example - - name: Depends on local seaography - run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/mysql/Cargo.toml + # - name: Generate entities + # run: sea-orm-cli generate entity -o ./examples/mysql/src/entities -u mysql://sea:sea@127.0.0.1/sakila + # - name: Generate Seaography project + # uses: actions-rs/cargo@v1 + # with: + # command: run + # args: > + # --package seaography-cli -- + # ./examples/mysql ./examples/mysql/src/entities mysql://sea:sea@127.0.0.1/sakila seaography-mysql-example + # - name: Depends on local seaography + # run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/mysql/Cargo.toml - name: Build example working-directory: ./examples/mysql run: cargo build @@ -248,13 +248,13 @@ jobs: profile: minimal toolchain: stable override: true - - name: Install sea-orm-cli - uses: baptiste0928/cargo-install@v2 - with: - crate: sea-orm-cli - version: '0.11.0' - - name: Remove generated folder - run: rm -rf ./examples/postgres/src + # - name: Install sea-orm-cli + # uses: baptiste0928/cargo-install@v2 + # with: + # crate: sea-orm-cli + # version: '0.11.0' + # - name: Remove generated folder + # run: rm -rf ./examples/postgres/src - name: Create DB run: psql -q postgres://sea:sea@localhost/postgres -c 'CREATE DATABASE "sakila"' - name: Import DB Schema @@ -263,19 +263,19 @@ jobs: - name: Import DB Data 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 - - name: Generate Seaography project - uses: actions-rs/cargo@v1 - with: - command: run - args: > - --package seaography-cli -- - ./examples/postgres ./examples/postgres/src/entities postgres://sea:sea@127.0.0.1/sakila?currentSchema=public seaography-postgres-example - - 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 + # - 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 + # - name: Generate Seaography project + # uses: actions-rs/cargo@v1 + # with: + # command: run + # args: > + # --package seaography-cli -- + # ./examples/postgres ./examples/postgres/src/entities postgres://sea:sea@127.0.0.1/sakila?currentSchema=public seaography-postgres-example + # - 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 - name: Build example working-directory: ./examples/postgres run: cargo build From f3923b86c229894eaffa28f00bcdf2a37e0f50c6 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 19 May 2023 22:37:16 +0800 Subject: [PATCH 14/20] Upgrade SeaQuery --- generator/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/Cargo.toml b/generator/Cargo.toml index 127efbb2..93c05c19 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -18,5 +18,5 @@ proc-macro2 = "1.0.51" syn = { version = "1.0.109", features = ["full"] } heck = "0.4.1" itertools = "0.10.5" -sea-query = { version = "0.28.3", default-features = false } +sea-query = { version = "0.29.0-rc.2", default-features = false } thiserror = "1.0.38" \ No newline at end of file From 3f6850b6395aa8f62bd5ad05ba4b4b232cfea2f4 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 19 May 2023 22:37:31 +0800 Subject: [PATCH 15/20] Upgrade SeaORM --- Cargo.toml | 2 +- examples/mysql/Cargo.toml | 2 +- examples/postgres/Cargo.toml | 2 +- examples/sqlite/Cargo.toml | 2 +- generator/src/templates/actix_cargo.toml | 2 +- generator/src/templates/poem_cargo.toml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0d6b7a8..72ebd21c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ categories = ["database"] [dependencies] async-graphql = { version = "5.0.6", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] } -sea-orm = { version = "0.12.0", default-features = false, git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["seaography"] } +sea-orm = { version = "0.12.0-rc.2", default-features = false, features = ["seaography"] } itertools = { version = "0.10.5" } heck = { version = "0.4.1" } diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml index 7e1ae2cf..66639c8e 100644 --- a/examples/mysql/Cargo.toml +++ b/examples/mysql/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] } +sea-orm = { version = "0.12.0-rc.2", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/examples/postgres/Cargo.toml b/examples/postgres/Cargo.toml index 2033acca..cfc8a0f6 100644 --- a/examples/postgres/Cargo.toml +++ b/examples/postgres/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] } +sea-orm = { version = "0.12.0-rc.2", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index ff99e412..595b9b9a 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["sqlx-sqlite", "runtime-async-std-native-tls", "seaography"] } +sea-orm = { version = "0.12.0-rc.2", features = ["sqlx-sqlite", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/generator/src/templates/actix_cargo.toml b/generator/src/templates/actix_cargo.toml index 8a7ff296..d180a072 100644 --- a/generator/src/templates/actix_cargo.toml +++ b/generator/src/templates/actix_cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls", "seaography"] } +sea-orm = { version = "0.12.0-rc.2", features = ["", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } diff --git a/generator/src/templates/poem_cargo.toml b/generator/src/templates/poem_cargo.toml index 5058b36d..634c4a1e 100644 --- a/generator/src/templates/poem_cargo.toml +++ b/generator/src/templates/poem_cargo.toml @@ -9,7 +9,7 @@ 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" } dotenv = "0.15.0" -sea-orm = { version = "0.12.0", git = "https://github.com/karatakis/sea-orm.git", branch = "seaography-generator", features = ["", "runtime-async-std-native-tls", "seaography"] } +sea-orm = { version = "0.12.0-rc.2", features = ["", "runtime-async-std-native-tls", "seaography"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.16" } From 73350e4664d42d7ac82ac9a3b35b94c8058d41b8 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 19 May 2023 22:38:16 +0800 Subject: [PATCH 16/20] Re-enable entity generation CI tests --- .github/workflows/tests.yaml | 148 +++++++++++++++++------------------ 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 72bf05ed..996d517a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -91,26 +91,26 @@ jobs: profile: minimal toolchain: stable override: true - # - name: Install sea-orm-cli - # uses: baptiste0928/cargo-install@v2 - # with: - # crate: sea-orm-cli - # version: '0.11.0' - # - name: Remove generated folder - # run: rm -rf ./examples/sqlite/src + - name: Install sea-orm-cli + uses: baptiste0928/cargo-install@v2 + with: + crate: sea-orm-cli + version: '0.12.0-rc.2' + - 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 - # - name: Generate Seaography project - # uses: actions-rs/cargo@v1 - # with: - # command: run - # args: > - # --package seaography-cli -- - # ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f poem - # - name: Depends on local seaography - # run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml + - name: Generate entities + 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: + command: run + args: > + --package seaography-cli -- + ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f poem + - name: Depends on local seaography + run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml - name: Build example working-directory: ./examples/sqlite run: cargo build @@ -131,26 +131,26 @@ jobs: profile: minimal toolchain: stable override: true - # - name: Install sea-orm-cli - # uses: baptiste0928/cargo-install@v2 - # with: - # crate: sea-orm-cli - # version: '0.11.0' - # - name: Remove generated folder - # run: rm -rf ./examples/sqlite/src + - name: Install sea-orm-cli + uses: baptiste0928/cargo-install@v2 + with: + crate: sea-orm-cli + version: '0.12.0-rc.2' + - 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 - # - name: Generate Seaography project - # uses: actions-rs/cargo@v1 - # with: - # command: run - # args: > - # --package seaography-cli -- - # ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f actix - # - name: Depends on local seaography - # run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml + - name: Generate entities + 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: + command: run + args: > + --package seaography-cli -- + ./examples/sqlite ./examples/sqlite/src/entities sqlite://sakila.db seaography-sqlite-example -f actix + - name: Depends on local seaography + run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml - name: Build example working-directory: ./examples/sqlite run: cargo build @@ -186,13 +186,13 @@ jobs: profile: minimal toolchain: stable override: true - # - name: Install sea-orm-cli - # uses: baptiste0928/cargo-install@v2 - # with: - # crate: sea-orm-cli - # version: '0.11.0' - # - name: Remove generated folder - # run: rm -rf ./examples/mysql/src + - name: Install sea-orm-cli + uses: baptiste0928/cargo-install@v2 + with: + crate: sea-orm-cli + version: '0.12.0-rc.2' + - name: Remove generated folder + run: rm -rf ./examples/mysql/src - name: Create DB run: mysql -uroot -h 127.0.0.1 mysql -e 'CREATE DATABASE `sakila`' - name: Grant Privilege @@ -203,17 +203,17 @@ jobs: - name: Import DB Data 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 - # - name: Generate Seaography project - # uses: actions-rs/cargo@v1 - # with: - # command: run - # args: > - # --package seaography-cli -- - # ./examples/mysql ./examples/mysql/src/entities mysql://sea:sea@127.0.0.1/sakila seaography-mysql-example - # - name: Depends on local seaography - # run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/mysql/Cargo.toml + - name: Generate entities + 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: + command: run + args: > + --package seaography-cli -- + ./examples/mysql ./examples/mysql/src/entities mysql://sea:sea@127.0.0.1/sakila seaography-mysql-example + - name: Depends on local seaography + run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/mysql/Cargo.toml - name: Build example working-directory: ./examples/mysql run: cargo build @@ -248,13 +248,13 @@ jobs: profile: minimal toolchain: stable override: true - # - name: Install sea-orm-cli - # uses: baptiste0928/cargo-install@v2 - # with: - # crate: sea-orm-cli - # version: '0.11.0' - # - name: Remove generated folder - # run: rm -rf ./examples/postgres/src + - name: Install sea-orm-cli + uses: baptiste0928/cargo-install@v2 + with: + crate: sea-orm-cli + version: '0.12.0-rc.2' + - name: Remove generated folder + run: rm -rf ./examples/postgres/src - name: Create DB run: psql -q postgres://sea:sea@localhost/postgres -c 'CREATE DATABASE "sakila"' - name: Import DB Schema @@ -263,19 +263,19 @@ jobs: - name: Import DB Data 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 - # - name: Generate Seaography project - # uses: actions-rs/cargo@v1 - # with: - # command: run - # args: > - # --package seaography-cli -- - # ./examples/postgres ./examples/postgres/src/entities postgres://sea:sea@127.0.0.1/sakila?currentSchema=public seaography-postgres-example - # - 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 + - 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 --seaography + - name: Generate Seaography project + uses: actions-rs/cargo@v1 + with: + command: run + args: > + --package seaography-cli -- + ./examples/postgres ./examples/postgres/src/entities postgres://sea:sea@127.0.0.1/sakila?currentSchema=public seaography-postgres-example + - 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 - name: Build example working-directory: ./examples/postgres run: cargo build From cb5f46d0a78d4f32a692211625b2b523c01bbf3a Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 19 May 2023 22:59:16 +0800 Subject: [PATCH 17/20] Fix --- examples/mysql/tests/query_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mysql/tests/query_tests.rs b/examples/mysql/tests/query_tests.rs index 67752765..d19fc994 100644 --- a/examples/mysql/tests/query_tests.rs +++ b/examples/mysql/tests/query_tests.rs @@ -3,7 +3,7 @@ use sea_orm::Database; use seaography_mysql_example::OrmDataloader; pub async fn get_schema() -> Schema { - let database = Database::connect("mysql://root:root@127.0.0.1/sakila") + let database = Database::connect("mysql://sea:sea@127.0.0.1/sakila") .await .unwrap(); let orm_dataloader: DataLoader = DataLoader::new( From 793069a3adb470bb01dfe39271aa97bfaf09c955 Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Sat, 22 Jul 2023 15:52:46 +0300 Subject: [PATCH 18/20] Update versions --- .github/workflows/tests.yaml | 8 ++++---- Cargo.toml | 6 +++--- cli/Cargo.toml | 4 ++-- generator/Cargo.toml | 12 ++++++------ generator/src/templates/actix_cargo.toml | 14 +++++++------- generator/src/templates/poem_cargo.toml | 16 ++++++++-------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 996d517a..6afad43e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -95,7 +95,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.12.0-rc.2' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/sqlite/src - name: Copy sample database @@ -135,7 +135,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.12.0-rc.2' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/sqlite/src - name: Copy sample database @@ -190,7 +190,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.12.0-rc.2' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/mysql/src - name: Create DB @@ -252,7 +252,7 @@ jobs: uses: baptiste0928/cargo-install@v2 with: crate: sea-orm-cli - version: '0.12.0-rc.2' + version: '0.12.0-rc.5' - name: Remove generated folder run: rm -rf ./examples/postgres/src - name: Create DB diff --git a/Cargo.toml b/Cargo.toml index 72ebd21c..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.12.0-rc.2", default-features = false, features = ["seaography"] } -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/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/generator/Cargo.toml b/generator/Cargo.toml index 93c05c19..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.29.0-rc.2", 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/templates/actix_cargo.toml b/generator/src/templates/actix_cargo.toml index d180a072..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.12.0-rc.2", features = ["", "runtime-async-std-native-tls", "seaography"] } -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_cargo.toml b/generator/src/templates/poem_cargo.toml index 634c4a1e..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.12.0-rc.2", features = ["", "runtime-async-std-native-tls", "seaography"] } -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 From 6cef25c21251ca7cf5155530d5692d3bc6108a0c Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Sat, 22 Jul 2023 15:52:53 +0300 Subject: [PATCH 19/20] Update examples --- .github/workflows/tests.yaml | 2 -- examples/mysql/Cargo.toml | 18 ++++++++-------- examples/mysql/src/entities/actor.rs | 4 ++-- examples/mysql/src/entities/address.rs | 10 ++++----- examples/mysql/src/entities/category.rs | 2 +- examples/mysql/src/entities/city.rs | 6 +++--- examples/mysql/src/entities/country.rs | 4 ++-- examples/mysql/src/entities/customer.rs | 10 ++++----- examples/mysql/src/entities/film.rs | 15 +++++++------ examples/mysql/src/entities/film_actor.rs | 6 +++--- examples/mysql/src/entities/film_category.rs | 4 ++-- examples/mysql/src/entities/film_text.rs | 2 +- examples/mysql/src/entities/inventory.rs | 10 ++++----- examples/mysql/src/entities/language.rs | 4 ++-- examples/mysql/src/entities/mod.rs | 2 +- examples/mysql/src/entities/payment.rs | 10 ++++----- examples/mysql/src/entities/prelude.rs | 2 +- examples/mysql/src/entities/rental.rs | 9 ++++---- .../src/entities/sea_orm_active_enums.rs | 2 +- examples/mysql/src/entities/staff.rs | 21 +++++++++++++++---- examples/mysql/src/entities/store.rs | 8 +++---- examples/mysql/src/query_root.rs | 18 ++++++++-------- examples/postgres/Cargo.toml | 18 ++++++++-------- examples/postgres/src/entities/actor.rs | 2 +- examples/postgres/src/entities/address.rs | 2 +- examples/postgres/src/entities/category.rs | 2 +- examples/postgres/src/entities/city.rs | 2 +- examples/postgres/src/entities/country.rs | 2 +- examples/postgres/src/entities/customer.rs | 2 +- examples/postgres/src/entities/film.rs | 2 +- examples/postgres/src/entities/film_actor.rs | 2 +- .../postgres/src/entities/film_category.rs | 2 +- examples/postgres/src/entities/inventory.rs | 2 +- examples/postgres/src/entities/language.rs | 2 +- examples/postgres/src/entities/mod.rs | 2 +- examples/postgres/src/entities/payment.rs | 2 +- examples/postgres/src/entities/prelude.rs | 2 +- examples/postgres/src/entities/rental.rs | 2 +- .../src/entities/sea_orm_active_enums.rs | 2 +- examples/postgres/src/entities/staff.rs | 2 +- examples/postgres/src/entities/store.rs | 2 +- examples/postgres/src/query_root.rs | 18 ++++++++-------- examples/sqlite/Cargo.toml | 18 ++++++++-------- examples/sqlite/src/entities/actor.rs | 2 +- examples/sqlite/src/entities/address.rs | 2 +- examples/sqlite/src/entities/category.rs | 2 +- examples/sqlite/src/entities/city.rs | 2 +- examples/sqlite/src/entities/country.rs | 2 +- examples/sqlite/src/entities/customer.rs | 2 +- examples/sqlite/src/entities/film.rs | 2 +- examples/sqlite/src/entities/film_actor.rs | 2 +- examples/sqlite/src/entities/film_category.rs | 2 +- examples/sqlite/src/entities/film_text.rs | 2 +- examples/sqlite/src/entities/inventory.rs | 2 +- examples/sqlite/src/entities/language.rs | 2 +- examples/sqlite/src/entities/mod.rs | 2 +- examples/sqlite/src/entities/payment.rs | 2 +- examples/sqlite/src/entities/prelude.rs | 2 +- examples/sqlite/src/entities/rental.rs | 2 +- examples/sqlite/src/entities/staff.rs | 2 +- examples/sqlite/src/entities/store.rs | 2 +- examples/sqlite/src/query_root.rs | 18 ++++++++-------- 62 files changed, 161 insertions(+), 152 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 6afad43e..3fff14ea 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -274,8 +274,6 @@ jobs: ./examples/postgres ./examples/postgres/src/entities postgres://sea:sea@127.0.0.1/sakila?currentSchema=public seaography-postgres-example - 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 - name: Build example working-directory: ./examples/postgres run: cargo build diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml index 66639c8e..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.12.0-rc.2", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] } -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 e528469a..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "actor")] pub struct Model { #[sea_orm(primary_key)] - pub actor_id: u16, + pub actor_id: i32, pub first_name: String, pub last_name: String, pub last_update: DateTimeUtc, diff --git a/examples/mysql/src/entities/address.rs b/examples/mysql/src/entities/address.rs index e089d953..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,15 +6,15 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "address")] pub struct Model { #[sea_orm(primary_key)] - pub address_id: u16, + pub address_id: i32, pub address: String, pub address2: Option, pub district: String, - pub city_id: u16, + pub city_id: i32, pub postal_code: Option, pub phone: String, - #[sea_orm(column_type = "custom(\"GEOMETRY\")")] - pub location: String, + #[sea_orm(column_type = "VarBinary(25)", nullable)] + pub location: Option>, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/category.rs b/examples/mysql/src/entities/category.rs index 8666f3a9..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.12.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/city.rs b/examples/mysql/src/entities/city.rs index 338fd16b..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,9 +6,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "city")] pub struct Model { #[sea_orm(primary_key)] - pub city_id: u16, + pub city_id: i32, pub city: String, - pub country_id: u16, + pub country_id: i32, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/country.rs b/examples/mysql/src/entities/country.rs index 94bf515b..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "country")] pub struct Model { #[sea_orm(primary_key)] - pub country_id: u16, + pub country_id: i32, pub country: String, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/customer.rs b/examples/mysql/src/entities/customer.rs index 42ef5be4..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,15 +6,15 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "customer")] pub struct Model { #[sea_orm(primary_key)] - pub customer_id: u16, - pub store_id: u8, + pub customer_id: i32, + pub store_id: i32, pub first_name: String, pub last_name: String, pub email: Option, - pub address_id: u16, + pub address_id: i32, pub active: i8, pub create_date: DateTime, - pub last_update: Option, + pub last_update: DateTimeUtc, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/examples/mysql/src/entities/film.rs b/examples/mysql/src/entities/film.rs index 73afd2fb..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.12.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::*; @@ -7,18 +7,17 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "film")] pub struct Model { #[sea_orm(primary_key)] - pub film_id: u16, + pub film_id: i32, pub title: String, #[sea_orm(column_type = "Text", nullable)] pub description: Option, - #[sea_orm(column_type = "Text", nullable)] - pub release_year: Option, - pub language_id: u8, - pub original_language_id: Option, - pub rental_duration: u8, + pub release_year: Option, + pub language_id: i32, + pub original_language_id: Option, + pub rental_duration: i32, #[sea_orm(column_type = "Decimal(Some((4, 2)))")] pub rental_rate: Decimal, - pub length: Option, + pub length: Option, #[sea_orm(column_type = "Decimal(Some((5, 2)))")] pub replacement_cost: Decimal, pub rating: Option, diff --git a/examples/mysql/src/entities/film_actor.rs b/examples/mysql/src/entities/film_actor.rs index 18bed4e3..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,9 +6,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "film_actor")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub actor_id: u16, + pub actor_id: i32, #[sea_orm(primary_key, auto_increment = false)] - pub film_id: u16, + pub film_id: i32, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/film_category.rs b/examples/mysql/src/entities/film_category.rs index be619a7e..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "film_category")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub film_id: u16, + pub film_id: i32, #[sea_orm(primary_key, auto_increment = false)] pub category_id: u8, pub last_update: DateTimeUtc, diff --git a/examples/mysql/src/entities/film_text.rs b/examples/mysql/src/entities/film_text.rs index 6949e8f0..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.12.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/inventory.rs b/examples/mysql/src/entities/inventory.rs index c6dd75c9..f483f722 100644 --- a/examples/mysql/src/entities/inventory.rs +++ b/examples/mysql/src/entities/inventory.rs @@ -1,14 +1,14 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "inventory")] pub struct Model { - #[sea_orm(primary_key, column_type = "custom(\"MEDIUMINT UNSIGNED\")")] - pub inventory_id: String, - pub film_id: u16, - pub store_id: u8, + #[sea_orm(primary_key)] + pub inventory_id: i32, + pub film_id: i32, + pub store_id: i32, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/language.rs b/examples/mysql/src/entities/language.rs index be7b55b1..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "language")] pub struct Model { #[sea_orm(primary_key)] - pub language_id: u8, + pub language_id: i32, pub name: String, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/mod.rs b/examples/mysql/src/entities/mod.rs index 2fe6c0aa..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.12.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 40d0042e..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,14 +6,14 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "payment")] pub struct Model { #[sea_orm(primary_key)] - pub payment_id: u16, - pub customer_id: u16, - pub staff_id: u8, + pub payment_id: i32, + pub customer_id: i32, + pub staff_id: i32, pub rental_id: Option, #[sea_orm(column_type = "Decimal(Some((5, 2)))")] pub amount: Decimal, pub payment_date: DateTime, - pub last_update: Option, + pub last_update: DateTimeUtc, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/examples/mysql/src/entities/prelude.rs b/examples/mysql/src/entities/prelude.rs index e0d0943f..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.12.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 37c4a549..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -8,11 +8,10 @@ pub struct Model { #[sea_orm(primary_key)] pub rental_id: i32, pub rental_date: DateTime, - #[sea_orm(column_type = "custom(\"MEDIUMINT UNSIGNED\")")] - pub inventory_id: String, - pub customer_id: u16, + pub inventory_id: i32, + pub customer_id: i32, pub return_date: Option, - pub staff_id: u8, + pub staff_id: i32, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/entities/sea_orm_active_enums.rs b/examples/mysql/src/entities/sea_orm_active_enums.rs index d0400bd8..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.12.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 7127da6e..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,14 +6,15 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "staff")] pub struct Model { #[sea_orm(primary_key)] - pub staff_id: u8, + pub staff_id: i32, pub first_name: String, pub last_name: String, - pub address_id: u16, + 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: u8, + pub store_id: i32, pub active: i8, pub username: String, pub password: Option, @@ -34,6 +35,14 @@ pub enum Relation { Payment, #[sea_orm(has_many = "super::rental::Entity")] Rental, + #[sea_orm( + belongs_to = "Entity", + from = "Column::ReportsToId", + to = "Column::StaffId", + on_update = "Cascade", + on_delete = "Restrict" + )] + SelfRef, #[sea_orm( belongs_to = "super::store::Entity", from = "Column::StoreId", @@ -78,6 +87,10 @@ pub enum RelatedEntity { 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 effa6334..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; @@ -6,10 +6,10 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "store")] pub struct Model { #[sea_orm(primary_key)] - pub store_id: u8, + pub store_id: i32, #[sea_orm(unique)] - pub manager_staff_id: u8, - pub address_id: u16, + pub manager_staff_id: i32, + pub address_id: i32, pub last_update: DateTimeUtc, } diff --git a/examples/mysql/src/query_root.rs b/examples/mysql/src/query_root.rs index 1f8a9cec..408d2132 100644 --- a/examples/mysql/src/query_root.rs +++ b/examples/mysql/src/query_root.rs @@ -15,22 +15,22 @@ pub fn schema( seaography::register_entities!( builder, [ - rental, film_actor, + rental, + category, staff, - address, - store, + country, film, - city, - payment, - inventory, - category, actor, - customer, language, + city, + inventory, film_text, film_category, - country, + customer, + store, + payment, + address, ] ); builder.register_enumeration::(); diff --git a/examples/postgres/Cargo.toml b/examples/postgres/Cargo.toml index cfc8a0f6..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.12.0-rc.2", features = ["sqlx-postgres", "runtime-async-std-native-tls", "seaography"] } -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 4e06075c..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.12.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/address.rs b/examples/postgres/src/entities/address.rs index 9fe493b3..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.12.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/category.rs b/examples/postgres/src/entities/category.rs index 82bbc533..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.12.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/city.rs b/examples/postgres/src/entities/city.rs index 335ce59b..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.12.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/country.rs b/examples/postgres/src/entities/country.rs index 215460ba..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.12.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/customer.rs b/examples/postgres/src/entities/customer.rs index 97b14eb6..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.12.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/film.rs b/examples/postgres/src/entities/film.rs index c8d939f0..d40204c6 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.12.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::*; diff --git a/examples/postgres/src/entities/film_actor.rs b/examples/postgres/src/entities/film_actor.rs index 4472d37f..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.12.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/film_category.rs b/examples/postgres/src/entities/film_category.rs index 7b6fc87a..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.12.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/inventory.rs b/examples/postgres/src/entities/inventory.rs index 56b54576..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.12.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/language.rs b/examples/postgres/src/entities/language.rs index 471b6b8a..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.12.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/mod.rs b/examples/postgres/src/entities/mod.rs index d6603858..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.12.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 d893f4a1..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.12.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/prelude.rs b/examples/postgres/src/entities/prelude.rs index cc16fc4b..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.12.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 65e5d566..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.12.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/sea_orm_active_enums.rs b/examples/postgres/src/entities/sea_orm_active_enums.rs index 61bcab20..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.12.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 d45df645..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.12.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/store.rs b/examples/postgres/src/entities/store.rs index d8d2ab6f..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/postgres/src/query_root.rs b/examples/postgres/src/query_root.rs index 71e6d468..cd4d19d4 100644 --- a/examples/postgres/src/query_root.rs +++ b/examples/postgres/src/query_root.rs @@ -15,21 +15,21 @@ pub fn schema( seaography::register_entities!( builder, [ - rental, film_actor, + rental, + category, staff, - address, - store, + country, film, - city, - payment, - inventory, - category, actor, - customer, language, + city, + inventory, film_category, - country, + customer, + store, + payment, + address, ] ); builder.register_enumeration::(); diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 595b9b9a..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.12.0-rc.2", features = ["sqlx-sqlite", "runtime-async-std-native-tls", "seaography"] } -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 a1d3b00e..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/address.rs b/examples/sqlite/src/entities/address.rs index cdfc9e6b..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/category.rs b/examples/sqlite/src/entities/category.rs index dd3d4ef0..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/city.rs b/examples/sqlite/src/entities/city.rs index 6d4b445a..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/country.rs b/examples/sqlite/src/entities/country.rs index b1d4c73d..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/customer.rs b/examples/sqlite/src/entities/customer.rs index 2c82bcae..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/film.rs b/examples/sqlite/src/entities/film.rs index dbf9f4ea..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/film_actor.rs b/examples/sqlite/src/entities/film_actor.rs index 2d97e3ec..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/film_category.rs b/examples/sqlite/src/entities/film_category.rs index 246fc8c4..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/film_text.rs b/examples/sqlite/src/entities/film_text.rs index 68904053..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/inventory.rs b/examples/sqlite/src/entities/inventory.rs index 8ea54d15..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/language.rs b/examples/sqlite/src/entities/language.rs index 5eebcaaf..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/mod.rs b/examples/sqlite/src/entities/mod.rs index e64a59d9..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.12.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 9eff525d..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/prelude.rs b/examples/sqlite/src/entities/prelude.rs index e0d0943f..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.12.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 1610c23c..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/staff.rs b/examples/sqlite/src/entities/staff.rs index 5d1ac66d..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/entities/store.rs b/examples/sqlite/src/entities/store.rs index 6472c991..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.12.0 +//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.0-rc.5 use sea_orm::entity::prelude::*; diff --git a/examples/sqlite/src/query_root.rs b/examples/sqlite/src/query_root.rs index 497efdad..b3b77bf1 100644 --- a/examples/sqlite/src/query_root.rs +++ b/examples/sqlite/src/query_root.rs @@ -15,22 +15,22 @@ pub fn schema( seaography::register_entities!( builder, [ - rental, film_actor, + rental, + category, staff, - address, - store, + country, film, - city, - payment, - inventory, - category, actor, - customer, language, + city, + inventory, film_text, film_category, - country, + customer, + store, + payment, + address, ] ); let schema = builder.schema_builder(); From 6e6881d7596de4d8682f5ddd4e14f8be5c788e89 Mon Sep 17 00:00:00 2001 From: Panagiotis Karatakis Date: Sat, 22 Jul 2023 16:28:34 +0300 Subject: [PATCH 20/20] Fix postgres test --- .github/workflows/tests.yaml | 2 ++ examples/postgres/src/entities/film.rs | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 3fff14ea..accf13ba 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -274,6 +274,8 @@ jobs: ./examples/postgres ./examples/postgres/src/entities postgres://sea:sea@127.0.0.1/sakila?currentSchema=public seaography-postgres-example - 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 "26,27d" ./examples/postgres/src/entities/film.rs - name: Build example working-directory: ./examples/postgres run: cargo build diff --git a/examples/postgres/src/entities/film.rs b/examples/postgres/src/entities/film.rs index d40204c6..5bd84b8c 100644 --- a/examples/postgres/src/entities/film.rs +++ b/examples/postgres/src/entities/film.rs @@ -23,8 +23,6 @@ pub struct Model { pub rating: Option, pub last_update: DateTime, pub special_features: Option>, - #[sea_orm(column_type = "custom(\"tsvector\")")] - pub fulltext: String, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]