From 8b25397ad7b8ae017c2d0dcf81146bd36a1add23 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 17 Dec 2021 17:41:34 +0800 Subject: [PATCH 1/4] Codegen SQLite --- sea-orm-cli/Cargo.toml | 3 +- sea-orm-cli/README.md | 5 +- sea-orm-cli/src/main.rs | 84 ++++++++++++++--------- sea-orm-codegen/src/entity/transformer.rs | 70 +++++++++++-------- 4 files changed, 99 insertions(+), 63 deletions(-) diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 0c8a06605..a5129efcc 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -22,9 +22,10 @@ clap = { version = "^2.33.3" } dotenv = { version = "^0.15" } async-std = { version = "^1.9", features = [ "attributes" ] } sea-orm-codegen = { version = "^0.4.2", path = "../sea-orm-codegen" } -sea-schema = { version = "0.3.0", default-features = false, features = [ +sea-schema = { version = "0.3.0", git = "https://github.com/SeaQL/sea-schema.git", branch = "sqlite-codegen", default-features = false, features = [ "debug-print", "sqlx-mysql", + "sqlx-sqlite", "sqlx-postgres", "discovery", "writer", diff --git a/sea-orm-cli/README.md b/sea-orm-cli/README.md index 531a3c465..bcf49100b 100644 --- a/sea-orm-cli/README.md +++ b/sea-orm-cli/README.md @@ -9,9 +9,12 @@ cargo run -- -h Running Entity Generator: ```sh -# MySQL (`--database-schema` option is ignored) +# MySQL (`--database-schema` option is ignored) cargo run -- generate entity -u mysql://sea:sea@localhost/bakery -o out +# SQLite (`--database-schema` option is ignored) +cargo run -- generate entity -u sqlite://bakery.db -o out + # PostgreSQL cargo run -- generate entity -u postgres://sea:sea@localhost/bakery -s public -o out ``` diff --git a/sea-orm-cli/src/main.rs b/sea-orm-cli/src/main.rs index 2c7848ce9..9fb52fb34 100644 --- a/sea-orm-cli/src/main.rs +++ b/sea-orm-cli/src/main.rs @@ -54,39 +54,18 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box) -> Result<(), Box) -> Result<(), Box { + use sea_schema::sqlite::SchemaDiscovery; + use sqlx::SqlitePool; + + let connection = SqlitePool::connect(url.as_str()).await?; + let schema_discovery = SchemaDiscovery::new(connection); + let schema = schema_discovery.discover().await?; + schema + .tables + .into_iter() + .filter(|schema| filter_tables(&schema.name)) + .filter(|schema| filter_hidden_tables(&schema.name)) + .map(|schema| schema.write()) + .collect() + } "postgres" | "postgresql" => { use sea_schema::postgres::discovery::SchemaDiscovery; use sqlx::PgPool; diff --git a/sea-orm-codegen/src/entity/transformer.rs b/sea-orm-codegen/src/entity/transformer.rs index 8c9cdd1c1..f9159b787 100644 --- a/sea-orm-codegen/src/entity/transformer.rs +++ b/sea-orm-codegen/src/entity/transformer.rs @@ -2,27 +2,19 @@ use crate::{ ActiveEnum, Column, ConjunctRelation, Entity, EntityWriter, Error, PrimaryKey, Relation, RelationType, }; -use sea_query::TableStatement; +use sea_query::{ColumnSpec, TableCreateStatement}; use std::collections::HashMap; #[derive(Clone, Debug)] pub struct EntityTransformer; impl EntityTransformer { - pub fn transform(table_stmts: Vec) -> Result { + pub fn transform(table_create_stmts: Vec) -> Result { let mut enums: HashMap = HashMap::new(); let mut inverse_relations: HashMap> = HashMap::new(); let mut conjunct_relations: HashMap> = HashMap::new(); let mut entities = HashMap::new(); - for table_stmt in table_stmts.into_iter() { - let table_create = match table_stmt { - TableStatement::Create(stmt) => stmt, - _ => { - return Err(Error::TransformError( - "TableStatement should be create".into(), - )) - } - }; + for table_create in table_create_stmts.into_iter() { let table_name = match table_create.get_table_name() { Some(table_ref) => match table_ref { sea_query::TableRef::Table(t) @@ -39,10 +31,22 @@ impl EntityTransformer { )) } }; + let mut primary_keys: Vec = Vec::new(); let columns: Vec = table_create .get_columns() .iter() - .map(|col_def| col_def.into()) + .map(|col_def| { + let primary_key = col_def + .get_column_spec() + .iter() + .any(|spec| matches!(spec, ColumnSpec::PrimaryKey)); + if primary_key { + primary_keys.push(PrimaryKey { + name: col_def.get_column_name(), + }); + } + col_def.into() + }) .map(|mut col: Column| { col.unique = table_create .get_indexes() @@ -99,20 +103,21 @@ impl EntityTransformer { }) .rev() .collect(); - let primary_keys = table_create - .get_indexes() - .iter() - .filter(|index| index.is_primary_key()) - .map(|index| { - index - .get_index_spec() - .get_column_names() - .into_iter() - .map(|name| PrimaryKey { name }) - .collect::>() - }) - .flatten() - .collect(); + primary_keys.extend( + table_create + .get_indexes() + .iter() + .filter(|index| index.is_primary_key()) + .map(|index| { + index + .get_index_spec() + .get_column_names() + .into_iter() + .map(|name| PrimaryKey { name }) + .collect::>() + }) + .flatten(), + ); let entity = Entity { table_name: table_name.clone(), columns, @@ -180,9 +185,18 @@ impl EntityTransformer { } } } - for (tbl_name, mut relations) in inverse_relations.into_iter() { + println!("inverse_relations: {:#?}", inverse_relations); + for (tbl_name, relations) in inverse_relations.into_iter() { if let Some(entity) = entities.get_mut(&tbl_name) { - entity.relations.append(&mut relations); + for relation in relations.into_iter() { + let duplicate_relation = entity + .relations + .iter() + .any(|rel| rel.ref_table == relation.ref_table); + if !duplicate_relation { + entity.relations.push(relation); + } + } } } for (tbl_name, mut conjunct_relations) in conjunct_relations.into_iter() { From 712f577bd61249446ce27baaebe71d426934e105 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 17 Dec 2021 17:46:24 +0800 Subject: [PATCH 2/4] Remove debugging --- sea-orm-codegen/src/entity/transformer.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sea-orm-codegen/src/entity/transformer.rs b/sea-orm-codegen/src/entity/transformer.rs index f9159b787..d526c98cd 100644 --- a/sea-orm-codegen/src/entity/transformer.rs +++ b/sea-orm-codegen/src/entity/transformer.rs @@ -185,7 +185,6 @@ impl EntityTransformer { } } } - println!("inverse_relations: {:#?}", inverse_relations); for (tbl_name, relations) in inverse_relations.into_iter() { if let Some(entity) = entities.get_mut(&tbl_name) { for relation in relations.into_iter() { From d0430289a9f69a02316d46f609f616030ac6e486 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 17 Dec 2021 18:11:35 +0800 Subject: [PATCH 3/4] Fixup --- sea-orm-cli/src/main.rs | 58 +++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/sea-orm-cli/src/main.rs b/sea-orm-cli/src/main.rs index 9fb52fb34..a2169510e 100644 --- a/sea-orm-cli/src/main.rs +++ b/sea-orm-cli/src/main.rs @@ -54,8 +54,10 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box) -> Result<(), Box { use sea_schema::mysql::discovery::SchemaDiscovery; use sqlx::MySqlPool; - // The database name should be the first element of the path string - // - // Throwing an error if there is no database name since it might be - // accepted by the database without it, while we're looking to dump - // information from a particular database - let database_name = url - .path_segments() - .unwrap_or_else(|| { - panic!( - "There is no database name as part of the url path: {}", - url.as_str() - ) - }) - .next() - .unwrap(); - - // An empty string as the database name is also an error - if database_name.is_empty() { - panic!( - "There is no database name as part of the url path: {}", - url.as_str() - ); - } - let connection = MySqlPool::connect(url.as_str()).await?; let schema_discovery = SchemaDiscovery::new(connection, database_name); let schema = schema_discovery.discover().await; From 18dd1d3e792adf51476248d21e136f1b5e1d5cad Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 17 Dec 2021 17:49:14 +0800 Subject: [PATCH 4/4] Add SQLite "sakila.db" demo [issues] --- .github/workflows/rust.yml | 2 +- issues/386/Cargo.toml | 11 ++ issues/386/src/compact/actor.rs | 27 +++++ issues/386/src/compact/address.rs | 61 +++++++++++ issues/386/src/compact/category.rs | 30 ++++++ issues/386/src/compact/city.rs | 42 ++++++++ issues/386/src/compact/country.rs | 30 ++++++ issues/386/src/compact/customer.rs | 69 +++++++++++++ issues/386/src/compact/film.rs | 75 ++++++++++++++ issues/386/src/compact/film_actor.rs | 47 +++++++++ issues/386/src/compact/film_category.rs | 51 +++++++++ issues/386/src/compact/film_text.rs | 28 +++++ issues/386/src/compact/inventory.rs | 55 ++++++++++ issues/386/src/compact/language.rs | 28 +++++ issues/386/src/compact/mod.rs | 20 ++++ issues/386/src/compact/payment.rs | 66 ++++++++++++ issues/386/src/compact/prelude.rs | 18 ++++ issues/386/src/compact/rental.rs | 73 +++++++++++++ issues/386/src/compact/staff.rs | 76 ++++++++++++++ issues/386/src/compact/store.rs | 64 ++++++++++++ issues/386/src/expanded/actor.rs | 73 +++++++++++++ issues/386/src/expanded/address.rs | 112 ++++++++++++++++++++ issues/386/src/expanded/category.rs | 70 +++++++++++++ issues/386/src/expanded/city.rs | 84 +++++++++++++++ issues/386/src/expanded/country.rs | 70 +++++++++++++ issues/386/src/expanded/customer.rs | 118 +++++++++++++++++++++ issues/386/src/expanded/film.rs | 126 +++++++++++++++++++++++ issues/386/src/expanded/film_actor.rs | 85 +++++++++++++++ issues/386/src/expanded/film_category.rs | 85 +++++++++++++++ issues/386/src/expanded/film_text.rs | 60 +++++++++++ issues/386/src/expanded/inventory.rs | 95 +++++++++++++++++ issues/386/src/expanded/language.rs | 60 +++++++++++ issues/386/src/expanded/mod.rs | 20 ++++ issues/386/src/expanded/payment.rs | 107 +++++++++++++++++++ issues/386/src/expanded/prelude.rs | 18 ++++ issues/386/src/expanded/rental.rs | 115 +++++++++++++++++++++ issues/386/src/expanded/staff.rs | 124 ++++++++++++++++++++++ issues/386/src/expanded/store.rs | 103 ++++++++++++++++++ issues/386/src/main.rs | 4 + 39 files changed, 2401 insertions(+), 1 deletion(-) create mode 100644 issues/386/Cargo.toml create mode 100644 issues/386/src/compact/actor.rs create mode 100644 issues/386/src/compact/address.rs create mode 100644 issues/386/src/compact/category.rs create mode 100644 issues/386/src/compact/city.rs create mode 100644 issues/386/src/compact/country.rs create mode 100644 issues/386/src/compact/customer.rs create mode 100644 issues/386/src/compact/film.rs create mode 100644 issues/386/src/compact/film_actor.rs create mode 100644 issues/386/src/compact/film_category.rs create mode 100644 issues/386/src/compact/film_text.rs create mode 100644 issues/386/src/compact/inventory.rs create mode 100644 issues/386/src/compact/language.rs create mode 100644 issues/386/src/compact/mod.rs create mode 100644 issues/386/src/compact/payment.rs create mode 100644 issues/386/src/compact/prelude.rs create mode 100644 issues/386/src/compact/rental.rs create mode 100644 issues/386/src/compact/staff.rs create mode 100644 issues/386/src/compact/store.rs create mode 100644 issues/386/src/expanded/actor.rs create mode 100644 issues/386/src/expanded/address.rs create mode 100644 issues/386/src/expanded/category.rs create mode 100644 issues/386/src/expanded/city.rs create mode 100644 issues/386/src/expanded/country.rs create mode 100644 issues/386/src/expanded/customer.rs create mode 100644 issues/386/src/expanded/film.rs create mode 100644 issues/386/src/expanded/film_actor.rs create mode 100644 issues/386/src/expanded/film_category.rs create mode 100644 issues/386/src/expanded/film_text.rs create mode 100644 issues/386/src/expanded/inventory.rs create mode 100644 issues/386/src/expanded/language.rs create mode 100644 issues/386/src/expanded/mod.rs create mode 100644 issues/386/src/expanded/payment.rs create mode 100644 issues/386/src/expanded/prelude.rs create mode 100644 issues/386/src/expanded/rental.rs create mode 100644 issues/386/src/expanded/staff.rs create mode 100644 issues/386/src/expanded/store.rs create mode 100644 issues/386/src/main.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4affff662..b96189048 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -316,7 +316,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - path: [86, 249, 262, 319, 324, 352, 356] + path: [86, 249, 262, 319, 324, 352, 356, 386] steps: - uses: actions/checkout@v2 diff --git a/issues/386/Cargo.toml b/issues/386/Cargo.toml new file mode 100644 index 000000000..f3a975f16 --- /dev/null +++ b/issues/386/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +# A separate workspace + +[package] +name = "sea-orm-issues-386" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls" ]} diff --git a/issues/386/src/compact/actor.rs b/issues/386/src/compact/actor.rs new file mode 100644 index 000000000..ad7248d62 --- /dev/null +++ b/issues/386/src/compact/actor.rs @@ -0,0 +1,27 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "actor")] +pub struct Model { + #[sea_orm(primary_key)] + pub actor_id: i32, + pub first_name: String, + pub last_name: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::film_actor::Entity")] + FilmActor, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/address.rs b/issues/386/src/compact/address.rs new file mode 100644 index 000000000..04541e3cc --- /dev/null +++ b/issues/386/src/compact/address.rs @@ -0,0 +1,61 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "address")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub address_id: i32, + pub address: String, + pub address2: Option, + pub district: String, + pub city_id: i32, + pub postal_code: Option, + pub phone: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::city::Entity", + from = "Column::CityId", + to = "super::city::Column::CityId", + on_update = "Cascade", + on_delete = "NoAction" + )] + City, + #[sea_orm(has_many = "super::customer::Entity")] + Customer, + #[sea_orm(has_many = "super::staff::Entity")] + Staff, + #[sea_orm(has_many = "super::store::Entity")] + Store, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::City.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/category.rs b/issues/386/src/compact/category.rs new file mode 100644 index 000000000..a7ff20f37 --- /dev/null +++ b/issues/386/src/compact/category.rs @@ -0,0 +1,30 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "category")] +pub struct Model { + #[sea_orm( + primary_key, + auto_increment = false, + column_type = "Custom(\"BLOB\".to_owned())" + )] + pub category_id: String, + pub name: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::film_category::Entity")] + FilmCategory, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/city.rs b/issues/386/src/compact/city.rs new file mode 100644 index 000000000..02d28b0d1 --- /dev/null +++ b/issues/386/src/compact/city.rs @@ -0,0 +1,42 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "city")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub city_id: i32, + pub city: String, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub country_id: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::country::Entity", + from = "Column::CountryId", + to = "super::country::Column::CountryId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Country, + #[sea_orm(has_many = "super::address::Entity")] + Address, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Country.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/country.rs b/issues/386/src/compact/country.rs new file mode 100644 index 000000000..9fe968298 --- /dev/null +++ b/issues/386/src/compact/country.rs @@ -0,0 +1,30 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "country")] +pub struct Model { + #[sea_orm( + primary_key, + auto_increment = false, + column_type = "Custom(\"BLOB\".to_owned())" + )] + pub country_id: String, + pub country: String, + pub last_update: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::city::Entity")] + City, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::City.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/customer.rs b/issues/386/src/compact/customer.rs new file mode 100644 index 000000000..95807b652 --- /dev/null +++ b/issues/386/src/compact/customer.rs @@ -0,0 +1,69 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "customer")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub customer_id: i32, + pub store_id: i32, + pub first_name: String, + pub last_name: String, + pub email: Option, + pub address_id: i32, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub active: String, + pub create_date: DateTime, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::address::Entity", + from = "Column::AddressId", + to = "super::address::Column::AddressId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Address, + #[sea_orm( + belongs_to = "super::store::Entity", + from = "Column::StoreId", + to = "super::store::Column::StoreId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Store, + #[sea_orm(has_many = "super::payment::Entity")] + Payment, + #[sea_orm(has_many = "super::rental::Entity")] + Rental, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Payment.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/film.rs b/issues/386/src/compact/film.rs new file mode 100644 index 000000000..39cf03306 --- /dev/null +++ b/issues/386/src/compact/film.rs @@ -0,0 +1,75 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "film")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub film_id: i32, + pub title: String, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())", nullable)] + pub description: Option, + pub release_year: Option, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub language_id: String, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())", nullable)] + pub original_language_id: Option, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub rental_duration: String, + #[sea_orm(column_type = "Decimal(Some((4, 2)))")] + pub rental_rate: Decimal, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())", nullable)] + pub length: Option, + #[sea_orm(column_type = "Decimal(Some((5, 2)))")] + pub replacement_cost: Decimal, + pub rating: Option, + pub special_features: Option, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::language::Entity", + from = "Column::OriginalLanguageId", + to = "super::language::Column::LanguageId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Language2, + #[sea_orm( + belongs_to = "super::language::Entity", + from = "Column::LanguageId", + to = "super::language::Column::LanguageId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Language1, + #[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, +} + +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() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/film_actor.rs b/issues/386/src/compact/film_actor.rs new file mode 100644 index 000000000..ba23ccb77 --- /dev/null +++ b/issues/386/src/compact/film_actor.rs @@ -0,0 +1,47 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "film_actor")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub actor_id: i32, + #[sea_orm(primary_key, auto_increment = false)] + pub film_id: i32, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::film::Entity", + from = "Column::FilmId", + to = "super::film::Column::FilmId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Film, + #[sea_orm( + belongs_to = "super::actor::Entity", + from = "Column::ActorId", + to = "super::actor::Column::ActorId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Actor, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Film.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Actor.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/film_category.rs b/issues/386/src/compact/film_category.rs new file mode 100644 index 000000000..222a773aa --- /dev/null +++ b/issues/386/src/compact/film_category.rs @@ -0,0 +1,51 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "film_category")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub film_id: i32, + #[sea_orm( + primary_key, + auto_increment = false, + column_type = "Custom(\"BLOB\".to_owned())" + )] + pub category_id: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::category::Entity", + from = "Column::CategoryId", + to = "super::category::Column::CategoryId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Category, + #[sea_orm( + belongs_to = "super::film::Entity", + from = "Column::FilmId", + to = "super::film::Column::FilmId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Film, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Category.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Film.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/film_text.rs b/issues/386/src/compact/film_text.rs new file mode 100644 index 000000000..d8f26b696 --- /dev/null +++ b/issues/386/src/compact/film_text.rs @@ -0,0 +1,28 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "film_text")] +pub struct Model { + #[sea_orm( + primary_key, + auto_increment = false, + column_type = "Custom(\"BLOB\".to_owned())" + )] + pub film_id: String, + pub title: String, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())", nullable)] + pub description: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/inventory.rs b/issues/386/src/compact/inventory.rs new file mode 100644 index 000000000..2f71f5c40 --- /dev/null +++ b/issues/386/src/compact/inventory.rs @@ -0,0 +1,55 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "inventory")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub inventory_id: i32, + pub film_id: i32, + pub store_id: i32, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::film::Entity", + from = "Column::FilmId", + to = "super::film::Column::FilmId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Film, + #[sea_orm( + belongs_to = "super::store::Entity", + from = "Column::StoreId", + to = "super::store::Column::StoreId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Store, + #[sea_orm(has_many = "super::rental::Entity")] + Rental, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Film.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/language.rs b/issues/386/src/compact/language.rs new file mode 100644 index 000000000..d77db3685 --- /dev/null +++ b/issues/386/src/compact/language.rs @@ -0,0 +1,28 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "language")] +pub struct Model { + #[sea_orm( + primary_key, + auto_increment = false, + column_type = "Custom(\"BLOB\".to_owned())" + )] + pub language_id: String, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub name: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/mod.rs b/issues/386/src/compact/mod.rs new file mode 100644 index 000000000..d7f098fca --- /dev/null +++ b/issues/386/src/compact/mod.rs @@ -0,0 +1,20 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +pub mod prelude; + +pub mod actor; +pub mod address; +pub mod category; +pub mod city; +pub mod country; +pub mod customer; +pub mod film; +pub mod film_actor; +pub mod film_category; +pub mod film_text; +pub mod inventory; +pub mod language; +pub mod payment; +pub mod rental; +pub mod staff; +pub mod store; diff --git a/issues/386/src/compact/payment.rs b/issues/386/src/compact/payment.rs new file mode 100644 index 000000000..43c494b4a --- /dev/null +++ b/issues/386/src/compact/payment.rs @@ -0,0 +1,66 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "payment")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub payment_id: i32, + pub customer_id: i32, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub staff_id: String, + pub rental_id: Option, + #[sea_orm(column_type = "Decimal(Some((5, 2)))")] + pub amount: Decimal, + pub payment_date: DateTime, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::staff::Entity", + from = "Column::StaffId", + to = "super::staff::Column::StaffId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Staff, + #[sea_orm( + belongs_to = "super::customer::Entity", + from = "Column::CustomerId", + to = "super::customer::Column::CustomerId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Customer, + #[sea_orm( + belongs_to = "super::rental::Entity", + from = "Column::RentalId", + to = "super::rental::Column::RentalId", + on_update = "Cascade", + on_delete = "SetNull" + )] + Rental, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/prelude.rs b/issues/386/src/compact/prelude.rs new file mode 100644 index 000000000..85cecd871 --- /dev/null +++ b/issues/386/src/compact/prelude.rs @@ -0,0 +1,18 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +pub use super::actor::Entity as Actor; +pub use super::address::Entity as Address; +pub use super::category::Entity as Category; +pub use super::city::Entity as City; +pub use super::country::Entity as Country; +pub use super::customer::Entity as Customer; +pub use super::film::Entity as Film; +pub use super::film_actor::Entity as FilmActor; +pub use super::film_category::Entity as FilmCategory; +pub use super::film_text::Entity as FilmText; +pub use super::inventory::Entity as Inventory; +pub use super::language::Entity as Language; +pub use super::payment::Entity as Payment; +pub use super::rental::Entity as Rental; +pub use super::staff::Entity as Staff; +pub use super::store::Entity as Store; diff --git a/issues/386/src/compact/rental.rs b/issues/386/src/compact/rental.rs new file mode 100644 index 000000000..15c7e9d90 --- /dev/null +++ b/issues/386/src/compact/rental.rs @@ -0,0 +1,73 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "rental")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub rental_id: i32, + pub rental_date: DateTime, + pub inventory_id: i32, + pub customer_id: i32, + pub return_date: Option, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub staff_id: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::customer::Entity", + from = "Column::CustomerId", + to = "super::customer::Column::CustomerId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Customer, + #[sea_orm( + belongs_to = "super::inventory::Entity", + from = "Column::InventoryId", + to = "super::inventory::Column::InventoryId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Inventory, + #[sea_orm( + belongs_to = "super::staff::Entity", + from = "Column::StaffId", + to = "super::staff::Column::StaffId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Staff, + #[sea_orm(has_many = "super::payment::Entity")] + Payment, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Inventory.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Payment.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/staff.rs b/issues/386/src/compact/staff.rs new file mode 100644 index 000000000..805e5a26f --- /dev/null +++ b/issues/386/src/compact/staff.rs @@ -0,0 +1,76 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "staff")] +pub struct Model { + #[sea_orm( + primary_key, + auto_increment = false, + column_type = "Custom(\"BLOB\".to_owned())" + )] + pub staff_id: String, + pub first_name: String, + pub last_name: String, + pub address_id: i32, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())", nullable)] + pub picture: Option, + pub email: Option, + pub store_id: i32, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub active: String, + pub username: String, + pub password: Option, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::address::Entity", + from = "Column::AddressId", + to = "super::address::Column::AddressId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Address, + #[sea_orm( + belongs_to = "super::store::Entity", + from = "Column::StoreId", + to = "super::store::Column::StoreId", + on_update = "Cascade", + on_delete = "NoAction" + )] + Store, + #[sea_orm(has_many = "super::payment::Entity")] + Payment, + #[sea_orm(has_many = "super::rental::Entity")] + Rental, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Payment.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/compact/store.rs b/issues/386/src/compact/store.rs new file mode 100644 index 000000000..f7e1eb4a4 --- /dev/null +++ b/issues/386/src/compact/store.rs @@ -0,0 +1,64 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "store")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub store_id: i32, + #[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")] + pub manager_staff_id: String, + pub address_id: i32, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::address::Entity", + from = "Column::AddressId", + to = "super::address::Column::AddressId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Address, + #[sea_orm( + belongs_to = "super::staff::Entity", + from = "Column::ManagerStaffId", + to = "super::staff::Column::StaffId", + on_update = "NoAction", + on_delete = "NoAction" + )] + Staff, + #[sea_orm(has_many = "super::customer::Entity")] + Customer, + #[sea_orm(has_many = "super::inventory::Entity")] + Inventory, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Inventory.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/actor.rs b/issues/386/src/expanded/actor.rs new file mode 100644 index 000000000..578d11b20 --- /dev/null +++ b/issues/386/src/expanded/actor.rs @@ -0,0 +1,73 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "actor" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub actor_id: i32, + pub first_name: String, + pub last_name: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + ActorId, + FirstName, + LastName, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + ActorId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + true + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + FilmActor, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::ActorId => ColumnType::Integer.def(), + Self::FirstName => ColumnType::String(None).def(), + Self::LastName => ColumnType::String(None).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::FilmActor => Entity::has_many(super::film_actor::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmActor.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/address.rs b/issues/386/src/expanded/address.rs new file mode 100644 index 000000000..e8b9a5b8c --- /dev/null +++ b/issues/386/src/expanded/address.rs @@ -0,0 +1,112 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "address" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub address_id: i32, + pub address: String, + pub address2: Option, + pub district: String, + pub city_id: i32, + pub postal_code: Option, + pub phone: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + AddressId, + Address, + Address2, + District, + CityId, + PostalCode, + Phone, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + AddressId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + City, + Customer, + Staff, + Store, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::AddressId => ColumnType::Integer.def(), + Self::Address => ColumnType::String(None).def(), + Self::Address2 => ColumnType::String(None).def().null(), + Self::District => ColumnType::String(None).def(), + Self::CityId => ColumnType::Integer.def(), + Self::PostalCode => ColumnType::String(None).def().null(), + Self::Phone => ColumnType::String(None).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::City => Entity::belongs_to(super::city::Entity) + .from(Column::CityId) + .to(super::city::Column::CityId) + .into(), + Self::Customer => Entity::has_many(super::customer::Entity).into(), + Self::Staff => Entity::has_many(super::staff::Entity).into(), + Self::Store => Entity::has_many(super::store::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::City.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/category.rs b/issues/386/src/expanded/category.rs new file mode 100644 index 000000000..4ce53b6a5 --- /dev/null +++ b/issues/386/src/expanded/category.rs @@ -0,0 +1,70 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "category" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub category_id: String, + pub name: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + CategoryId, + Name, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + CategoryId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = String; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + FilmCategory, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::CategoryId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::Name => ColumnType::String(None).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::FilmCategory => Entity::has_many(super::film_category::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::FilmCategory.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/city.rs b/issues/386/src/expanded/city.rs new file mode 100644 index 000000000..eb4010d20 --- /dev/null +++ b/issues/386/src/expanded/city.rs @@ -0,0 +1,84 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "city" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub city_id: i32, + pub city: String, + pub country_id: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + CityId, + City, + CountryId, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + CityId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Country, + Address, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::CityId => ColumnType::Integer.def(), + Self::City => ColumnType::String(None).def(), + Self::CountryId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Country => Entity::belongs_to(super::country::Entity) + .from(Column::CountryId) + .to(super::country::Column::CountryId) + .into(), + Self::Address => Entity::has_many(super::address::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Country.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/country.rs b/issues/386/src/expanded/country.rs new file mode 100644 index 000000000..5901ccbca --- /dev/null +++ b/issues/386/src/expanded/country.rs @@ -0,0 +1,70 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "country" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub country_id: String, + pub country: String, + pub last_update: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + CountryId, + Country, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + CountryId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = String; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + City, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::CountryId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::Country => ColumnType::String(None).def(), + Self::LastUpdate => ColumnType::Timestamp.def().null(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::City => Entity::has_many(super::city::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::City.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/customer.rs b/issues/386/src/expanded/customer.rs new file mode 100644 index 000000000..1adbaa664 --- /dev/null +++ b/issues/386/src/expanded/customer.rs @@ -0,0 +1,118 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "customer" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub customer_id: i32, + pub store_id: i32, + pub first_name: String, + pub last_name: String, + pub email: Option, + pub address_id: i32, + pub active: String, + pub create_date: DateTime, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + CustomerId, + StoreId, + FirstName, + LastName, + Email, + AddressId, + Active, + CreateDate, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + CustomerId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Address, + Store, + Payment, + Rental, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::CustomerId => ColumnType::Integer.def(), + Self::StoreId => ColumnType::Integer.def(), + Self::FirstName => ColumnType::String(None).def(), + Self::LastName => ColumnType::String(None).def(), + Self::Email => ColumnType::String(None).def().null(), + Self::AddressId => ColumnType::Integer.def(), + Self::Active => ColumnType::Custom("BLOB".to_owned()).def(), + Self::CreateDate => ColumnType::Timestamp.def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Address => Entity::belongs_to(super::address::Entity) + .from(Column::AddressId) + .to(super::address::Column::AddressId) + .into(), + Self::Store => Entity::belongs_to(super::store::Entity) + .from(Column::StoreId) + .to(super::store::Column::StoreId) + .into(), + Self::Payment => Entity::has_many(super::payment::Entity).into(), + Self::Rental => Entity::has_many(super::rental::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Payment.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/film.rs b/issues/386/src/expanded/film.rs new file mode 100644 index 000000000..b4e12ce33 --- /dev/null +++ b/issues/386/src/expanded/film.rs @@ -0,0 +1,126 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "film" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub film_id: i32, + pub title: String, + pub description: Option, + pub release_year: Option, + pub language_id: String, + pub original_language_id: Option, + pub rental_duration: String, + pub rental_rate: Decimal, + pub length: Option, + pub replacement_cost: Decimal, + pub rating: Option, + pub special_features: Option, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + FilmId, + Title, + Description, + ReleaseYear, + LanguageId, + OriginalLanguageId, + RentalDuration, + RentalRate, + Length, + ReplacementCost, + Rating, + SpecialFeatures, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + FilmId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Language2, + Language1, + FilmActor, + FilmCategory, + Inventory, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::FilmId => ColumnType::Integer.def(), + Self::Title => ColumnType::String(None).def(), + Self::Description => ColumnType::Custom("BLOB".to_owned()).def().null(), + Self::ReleaseYear => ColumnType::String(None).def().null(), + Self::LanguageId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::OriginalLanguageId => ColumnType::Custom("BLOB".to_owned()).def().null(), + Self::RentalDuration => ColumnType::Custom("BLOB".to_owned()).def(), + Self::RentalRate => ColumnType::Decimal(Some((4u32, 2u32))).def(), + Self::Length => ColumnType::Custom("BLOB".to_owned()).def().null(), + Self::ReplacementCost => ColumnType::Decimal(Some((5u32, 2u32))).def(), + Self::Rating => ColumnType::String(None).def().null(), + Self::SpecialFeatures => ColumnType::String(None).def().null(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Language2 => Entity::belongs_to(super::language::Entity) + .from(Column::OriginalLanguageId) + .to(super::language::Column::LanguageId) + .into(), + Self::Language1 => Entity::belongs_to(super::language::Entity) + .from(Column::LanguageId) + .to(super::language::Column::LanguageId) + .into(), + Self::FilmActor => Entity::has_many(super::film_actor::Entity).into(), + Self::FilmCategory => Entity::has_many(super::film_category::Entity).into(), + Self::Inventory => Entity::has_many(super::inventory::Entity).into(), + } + } +} + +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() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/film_actor.rs b/issues/386/src/expanded/film_actor.rs new file mode 100644 index 000000000..86211cec0 --- /dev/null +++ b/issues/386/src/expanded/film_actor.rs @@ -0,0 +1,85 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "film_actor" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub actor_id: i32, + pub film_id: i32, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + ActorId, + FilmId, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + ActorId, + FilmId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = (i32, i32); + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Film, + Actor, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::ActorId => ColumnType::Integer.def(), + Self::FilmId => ColumnType::Integer.def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Film => Entity::belongs_to(super::film::Entity) + .from(Column::FilmId) + .to(super::film::Column::FilmId) + .into(), + Self::Actor => Entity::belongs_to(super::actor::Entity) + .from(Column::ActorId) + .to(super::actor::Column::ActorId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Film.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Actor.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/film_category.rs b/issues/386/src/expanded/film_category.rs new file mode 100644 index 000000000..c1cc118af --- /dev/null +++ b/issues/386/src/expanded/film_category.rs @@ -0,0 +1,85 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "film_category" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub film_id: i32, + pub category_id: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + FilmId, + CategoryId, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + FilmId, + CategoryId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = (i32, String); + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Category, + Film, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::FilmId => ColumnType::Integer.def(), + Self::CategoryId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Category => Entity::belongs_to(super::category::Entity) + .from(Column::CategoryId) + .to(super::category::Column::CategoryId) + .into(), + Self::Film => Entity::belongs_to(super::film::Entity) + .from(Column::FilmId) + .to(super::film::Column::FilmId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Category.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Film.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/film_text.rs b/issues/386/src/expanded/film_text.rs new file mode 100644 index 000000000..87dbeda46 --- /dev/null +++ b/issues/386/src/expanded/film_text.rs @@ -0,0 +1,60 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "film_text" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub film_id: String, + pub title: String, + pub description: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + FilmId, + Title, + Description, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + FilmId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = String; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::FilmId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::Title => ColumnType::String(None).def(), + Self::Description => ColumnType::Custom("BLOB".to_owned()).def().null(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/inventory.rs b/issues/386/src/expanded/inventory.rs new file mode 100644 index 000000000..dbbb412b4 --- /dev/null +++ b/issues/386/src/expanded/inventory.rs @@ -0,0 +1,95 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "inventory" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub inventory_id: i32, + pub film_id: i32, + pub store_id: i32, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + InventoryId, + FilmId, + StoreId, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + InventoryId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Film, + Store, + Rental, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::InventoryId => ColumnType::Integer.def(), + Self::FilmId => ColumnType::Integer.def(), + Self::StoreId => ColumnType::Integer.def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Film => Entity::belongs_to(super::film::Entity) + .from(Column::FilmId) + .to(super::film::Column::FilmId) + .into(), + Self::Store => Entity::belongs_to(super::store::Entity) + .from(Column::StoreId) + .to(super::store::Column::StoreId) + .into(), + Self::Rental => Entity::has_many(super::rental::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Film.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/language.rs b/issues/386/src/expanded/language.rs new file mode 100644 index 000000000..cffd118e0 --- /dev/null +++ b/issues/386/src/expanded/language.rs @@ -0,0 +1,60 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "language" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub language_id: String, + pub name: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + LanguageId, + Name, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + LanguageId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = String; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::LanguageId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::Name => ColumnType::Custom("BLOB".to_owned()).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/mod.rs b/issues/386/src/expanded/mod.rs new file mode 100644 index 000000000..d7f098fca --- /dev/null +++ b/issues/386/src/expanded/mod.rs @@ -0,0 +1,20 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +pub mod prelude; + +pub mod actor; +pub mod address; +pub mod category; +pub mod city; +pub mod country; +pub mod customer; +pub mod film; +pub mod film_actor; +pub mod film_category; +pub mod film_text; +pub mod inventory; +pub mod language; +pub mod payment; +pub mod rental; +pub mod staff; +pub mod store; diff --git a/issues/386/src/expanded/payment.rs b/issues/386/src/expanded/payment.rs new file mode 100644 index 000000000..7977464bf --- /dev/null +++ b/issues/386/src/expanded/payment.rs @@ -0,0 +1,107 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "payment" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub payment_id: i32, + pub customer_id: i32, + pub staff_id: String, + pub rental_id: Option, + pub amount: Decimal, + pub payment_date: DateTime, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + PaymentId, + CustomerId, + StaffId, + RentalId, + Amount, + PaymentDate, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + PaymentId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Staff, + Customer, + Rental, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::PaymentId => ColumnType::Integer.def(), + Self::CustomerId => ColumnType::Integer.def(), + Self::StaffId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::RentalId => ColumnType::Integer.def().null(), + Self::Amount => ColumnType::Decimal(Some((5u32, 2u32))).def(), + Self::PaymentDate => ColumnType::Timestamp.def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Staff => Entity::belongs_to(super::staff::Entity) + .from(Column::StaffId) + .to(super::staff::Column::StaffId) + .into(), + Self::Customer => Entity::belongs_to(super::customer::Entity) + .from(Column::CustomerId) + .to(super::customer::Column::CustomerId) + .into(), + Self::Rental => Entity::belongs_to(super::rental::Entity) + .from(Column::RentalId) + .to(super::rental::Column::RentalId) + .into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/prelude.rs b/issues/386/src/expanded/prelude.rs new file mode 100644 index 000000000..85cecd871 --- /dev/null +++ b/issues/386/src/expanded/prelude.rs @@ -0,0 +1,18 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +pub use super::actor::Entity as Actor; +pub use super::address::Entity as Address; +pub use super::category::Entity as Category; +pub use super::city::Entity as City; +pub use super::country::Entity as Country; +pub use super::customer::Entity as Customer; +pub use super::film::Entity as Film; +pub use super::film_actor::Entity as FilmActor; +pub use super::film_category::Entity as FilmCategory; +pub use super::film_text::Entity as FilmText; +pub use super::inventory::Entity as Inventory; +pub use super::language::Entity as Language; +pub use super::payment::Entity as Payment; +pub use super::rental::Entity as Rental; +pub use super::staff::Entity as Staff; +pub use super::store::Entity as Store; diff --git a/issues/386/src/expanded/rental.rs b/issues/386/src/expanded/rental.rs new file mode 100644 index 000000000..952a0285a --- /dev/null +++ b/issues/386/src/expanded/rental.rs @@ -0,0 +1,115 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "rental" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub rental_id: i32, + pub rental_date: DateTime, + pub inventory_id: i32, + pub customer_id: i32, + pub return_date: Option, + pub staff_id: String, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + RentalId, + RentalDate, + InventoryId, + CustomerId, + ReturnDate, + StaffId, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + RentalId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Customer, + Inventory, + Staff, + Payment, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::RentalId => ColumnType::Integer.def(), + Self::RentalDate => ColumnType::Timestamp.def(), + Self::InventoryId => ColumnType::Integer.def(), + Self::CustomerId => ColumnType::Integer.def(), + Self::ReturnDate => ColumnType::Timestamp.def().null(), + Self::StaffId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Customer => Entity::belongs_to(super::customer::Entity) + .from(Column::CustomerId) + .to(super::customer::Column::CustomerId) + .into(), + Self::Inventory => Entity::belongs_to(super::inventory::Entity) + .from(Column::InventoryId) + .to(super::inventory::Column::InventoryId) + .into(), + Self::Staff => Entity::belongs_to(super::staff::Entity) + .from(Column::StaffId) + .to(super::staff::Column::StaffId) + .into(), + Self::Payment => Entity::has_many(super::payment::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Inventory.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Payment.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/staff.rs b/issues/386/src/expanded/staff.rs new file mode 100644 index 000000000..a24721cf4 --- /dev/null +++ b/issues/386/src/expanded/staff.rs @@ -0,0 +1,124 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "staff" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub staff_id: String, + pub first_name: String, + pub last_name: String, + pub address_id: i32, + pub picture: Option, + pub email: Option, + pub store_id: i32, + pub active: String, + pub username: String, + pub password: Option, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + StaffId, + FirstName, + LastName, + AddressId, + Picture, + Email, + StoreId, + Active, + Username, + Password, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + StaffId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = String; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Address, + Store, + Payment, + Rental, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::StaffId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::FirstName => ColumnType::String(None).def(), + Self::LastName => ColumnType::String(None).def(), + Self::AddressId => ColumnType::Integer.def(), + Self::Picture => ColumnType::Custom("BLOB".to_owned()).def().null(), + Self::Email => ColumnType::String(None).def().null(), + Self::StoreId => ColumnType::Integer.def(), + Self::Active => ColumnType::Custom("BLOB".to_owned()).def(), + Self::Username => ColumnType::String(None).def(), + Self::Password => ColumnType::String(None).def().null(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Address => Entity::belongs_to(super::address::Entity) + .from(Column::AddressId) + .to(super::address::Column::AddressId) + .into(), + Self::Store => Entity::belongs_to(super::store::Entity) + .from(Column::StoreId) + .to(super::store::Column::StoreId) + .into(), + Self::Payment => Entity::has_many(super::payment::Entity).into(), + Self::Rental => Entity::has_many(super::rental::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Store.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Payment.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Rental.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/expanded/store.rs b/issues/386/src/expanded/store.rs new file mode 100644 index 000000000..1d04fd666 --- /dev/null +++ b/issues/386/src/expanded/store.rs @@ -0,0 +1,103 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.4.2 + +use sea_orm::entity::prelude::*; + +#[derive(Copy, Clone, Default, Debug, DeriveEntity)] +pub struct Entity; + +impl EntityName for Entity { + fn table_name(&self) -> &str { + "store" + } +} + +#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)] +pub struct Model { + pub store_id: i32, + pub manager_staff_id: String, + pub address_id: i32, + pub last_update: DateTime, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] +pub enum Column { + StoreId, + ManagerStaffId, + AddressId, + LastUpdate, +} + +#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] +pub enum PrimaryKey { + StoreId, +} + +impl PrimaryKeyTrait for PrimaryKey { + type ValueType = i32; + fn auto_increment() -> bool { + false + } +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Address, + Staff, + Customer, + Inventory, +} + +impl ColumnTrait for Column { + type EntityName = Entity; + fn def(&self) -> ColumnDef { + match self { + Self::StoreId => ColumnType::Integer.def(), + Self::ManagerStaffId => ColumnType::Custom("BLOB".to_owned()).def(), + Self::AddressId => ColumnType::Integer.def(), + Self::LastUpdate => ColumnType::Timestamp.def(), + } + } +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Address => Entity::belongs_to(super::address::Entity) + .from(Column::AddressId) + .to(super::address::Column::AddressId) + .into(), + Self::Staff => Entity::belongs_to(super::staff::Entity) + .from(Column::ManagerStaffId) + .to(super::staff::Column::StaffId) + .into(), + Self::Customer => Entity::has_many(super::customer::Entity).into(), + Self::Inventory => Entity::has_many(super::inventory::Entity).into(), + } + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Address.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Staff.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Customer.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Inventory.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/issues/386/src/main.rs b/issues/386/src/main.rs new file mode 100644 index 000000000..c76f4650a --- /dev/null +++ b/issues/386/src/main.rs @@ -0,0 +1,4 @@ +mod compact; +mod expanded; + +pub fn main() {}