Codegen SQLite (#386)
* Codegen SQLite * Remove debugging * Fixup * Add SQLite "sakila.db" demo [issues]
This commit is contained in:
parent
2d5aa2a61b
commit
9036d27da7
2
.github/workflows/rust.yml
vendored
2
.github/workflows/rust.yml
vendored
@ -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
|
||||
|
||||
|
11
issues/386/Cargo.toml
Normal file
11
issues/386/Cargo.toml
Normal file
@ -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" ]}
|
27
issues/386/src/compact/actor.rs
Normal file
27
issues/386/src/compact/actor.rs
Normal file
@ -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<super::film_actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmActor.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
61
issues/386/src/compact/address.rs
Normal file
61
issues/386/src/compact/address.rs
Normal file
@ -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<String>,
|
||||
pub district: String,
|
||||
pub city_id: i32,
|
||||
pub postal_code: Option<String>,
|
||||
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<super::city::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::City.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
30
issues/386/src/compact/category.rs
Normal file
30
issues/386/src/compact/category.rs
Normal file
@ -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<super::film_category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmCategory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
42
issues/386/src/compact/city.rs
Normal file
42
issues/386/src/compact/city.rs
Normal file
@ -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<super::country::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Country.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
30
issues/386/src/compact/country.rs
Normal file
30
issues/386/src/compact/country.rs
Normal file
@ -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<DateTime>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::city::Entity")]
|
||||
City,
|
||||
}
|
||||
|
||||
impl Related<super::city::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::City.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
69
issues/386/src/compact/customer.rs
Normal file
69
issues/386/src/compact/customer.rs
Normal file
@ -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<String>,
|
||||
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<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::payment::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Payment.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
75
issues/386/src/compact/film.rs
Normal file
75
issues/386/src/compact/film.rs
Normal file
@ -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<String>,
|
||||
pub release_year: Option<String>,
|
||||
#[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<String>,
|
||||
#[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<String>,
|
||||
#[sea_orm(column_type = "Decimal(Some((5, 2)))")]
|
||||
pub replacement_cost: Decimal,
|
||||
pub rating: Option<String>,
|
||||
pub special_features: Option<String>,
|
||||
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<super::film_actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmActor.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::film_category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmCategory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::inventory::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Inventory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
47
issues/386/src/compact/film_actor.rs
Normal file
47
issues/386/src/compact/film_actor.rs
Normal file
@ -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<super::film::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Film.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Actor.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
51
issues/386/src/compact/film_category.rs
Normal file
51
issues/386/src/compact/film_category.rs
Normal file
@ -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<super::category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Category.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::film::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Film.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
28
issues/386/src/compact/film_text.rs
Normal file
28
issues/386/src/compact/film_text.rs
Normal file
@ -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<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl RelationTrait for Relation {
|
||||
fn def(&self) -> RelationDef {
|
||||
panic!("No RelationDef")
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
55
issues/386/src/compact/inventory.rs
Normal file
55
issues/386/src/compact/inventory.rs
Normal file
@ -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<super::film::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Film.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
28
issues/386/src/compact/language.rs
Normal file
28
issues/386/src/compact/language.rs
Normal file
@ -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 {}
|
20
issues/386/src/compact/mod.rs
Normal file
20
issues/386/src/compact/mod.rs
Normal file
@ -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;
|
66
issues/386/src/compact/payment.rs
Normal file
66
issues/386/src/compact/payment.rs
Normal file
@ -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<i32>,
|
||||
#[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<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
18
issues/386/src/compact/prelude.rs
Normal file
18
issues/386/src/compact/prelude.rs
Normal file
@ -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;
|
73
issues/386/src/compact/rental.rs
Normal file
73
issues/386/src/compact/rental.rs
Normal file
@ -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<DateTime>,
|
||||
#[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<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::inventory::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Inventory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::payment::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Payment.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
76
issues/386/src/compact/staff.rs
Normal file
76
issues/386/src/compact/staff.rs
Normal file
@ -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<String>,
|
||||
pub email: Option<String>,
|
||||
pub store_id: i32,
|
||||
#[sea_orm(column_type = "Custom(\"BLOB\".to_owned())")]
|
||||
pub active: String,
|
||||
pub username: String,
|
||||
pub password: Option<String>,
|
||||
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<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::payment::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Payment.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
64
issues/386/src/compact/store.rs
Normal file
64
issues/386/src/compact/store.rs
Normal file
@ -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<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::inventory::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Inventory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
73
issues/386/src/expanded/actor.rs
Normal file
73
issues/386/src/expanded/actor.rs
Normal file
@ -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<super::film_actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmActor.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
112
issues/386/src/expanded/address.rs
Normal file
112
issues/386/src/expanded/address.rs
Normal file
@ -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<String>,
|
||||
pub district: String,
|
||||
pub city_id: i32,
|
||||
pub postal_code: Option<String>,
|
||||
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<super::city::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::City.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
70
issues/386/src/expanded/category.rs
Normal file
70
issues/386/src/expanded/category.rs
Normal file
@ -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<super::film_category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmCategory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
84
issues/386/src/expanded/city.rs
Normal file
84
issues/386/src/expanded/city.rs
Normal file
@ -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<super::country::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Country.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
70
issues/386/src/expanded/country.rs
Normal file
70
issues/386/src/expanded/country.rs
Normal file
@ -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<DateTime>,
|
||||
}
|
||||
|
||||
#[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<super::city::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::City.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
118
issues/386/src/expanded/customer.rs
Normal file
118
issues/386/src/expanded/customer.rs
Normal file
@ -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<String>,
|
||||
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<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::payment::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Payment.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
126
issues/386/src/expanded/film.rs
Normal file
126
issues/386/src/expanded/film.rs
Normal file
@ -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<String>,
|
||||
pub release_year: Option<String>,
|
||||
pub language_id: String,
|
||||
pub original_language_id: Option<String>,
|
||||
pub rental_duration: String,
|
||||
pub rental_rate: Decimal,
|
||||
pub length: Option<String>,
|
||||
pub replacement_cost: Decimal,
|
||||
pub rating: Option<String>,
|
||||
pub special_features: Option<String>,
|
||||
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<super::film_actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmActor.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::film_category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::FilmCategory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::inventory::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Inventory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
85
issues/386/src/expanded/film_actor.rs
Normal file
85
issues/386/src/expanded/film_actor.rs
Normal file
@ -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<super::film::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Film.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Actor.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
85
issues/386/src/expanded/film_category.rs
Normal file
85
issues/386/src/expanded/film_category.rs
Normal file
@ -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<super::category::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Category.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::film::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Film.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
60
issues/386/src/expanded/film_text.rs
Normal file
60
issues/386/src/expanded/film_text.rs
Normal file
@ -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<String>,
|
||||
}
|
||||
|
||||
#[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 {}
|
95
issues/386/src/expanded/inventory.rs
Normal file
95
issues/386/src/expanded/inventory.rs
Normal file
@ -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<super::film::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Film.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
60
issues/386/src/expanded/language.rs
Normal file
60
issues/386/src/expanded/language.rs
Normal file
@ -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 {}
|
20
issues/386/src/expanded/mod.rs
Normal file
20
issues/386/src/expanded/mod.rs
Normal file
@ -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;
|
107
issues/386/src/expanded/payment.rs
Normal file
107
issues/386/src/expanded/payment.rs
Normal file
@ -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<i32>,
|
||||
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<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
18
issues/386/src/expanded/prelude.rs
Normal file
18
issues/386/src/expanded/prelude.rs
Normal file
@ -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;
|
115
issues/386/src/expanded/rental.rs
Normal file
115
issues/386/src/expanded/rental.rs
Normal file
@ -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<DateTime>,
|
||||
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<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::inventory::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Inventory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::payment::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Payment.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
124
issues/386/src/expanded/staff.rs
Normal file
124
issues/386/src/expanded/staff.rs
Normal file
@ -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<String>,
|
||||
pub email: Option<String>,
|
||||
pub store_id: i32,
|
||||
pub active: String,
|
||||
pub username: String,
|
||||
pub password: Option<String>,
|
||||
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<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::store::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Store.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::payment::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Payment.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::rental::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Rental.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
103
issues/386/src/expanded/store.rs
Normal file
103
issues/386/src/expanded/store.rs
Normal file
@ -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<super::address::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Address.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::staff::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Staff.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::customer::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Customer.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::inventory::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Inventory.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
4
issues/386/src/main.rs
Normal file
4
issues/386/src/main.rs
Normal file
@ -0,0 +1,4 @@
|
||||
mod compact;
|
||||
mod expanded;
|
||||
|
||||
pub fn main() {}
|
@ -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",
|
||||
|
@ -12,6 +12,9 @@ Running Entity Generator:
|
||||
# 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
|
||||
```
|
||||
|
@ -53,6 +53,10 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
let url_password = url.password();
|
||||
let url_host = url.host_str();
|
||||
|
||||
let is_sqlite = url.scheme() == "sqlite";
|
||||
|
||||
// Skip checking if it's SQLite
|
||||
if !is_sqlite {
|
||||
// Panic on any that are missing
|
||||
if url_username.is_empty() {
|
||||
panic!("No username was found in the database url");
|
||||
@ -63,7 +67,25 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
if url_host.is_none() {
|
||||
panic!("No host was found in the database url");
|
||||
}
|
||||
}
|
||||
|
||||
// Closures for filtering tables
|
||||
let filter_tables = |table: &str| -> bool {
|
||||
if !tables.is_empty() {
|
||||
return tables.contains(&table);
|
||||
}
|
||||
|
||||
true
|
||||
};
|
||||
let filter_hidden_tables = |table: &str| -> bool {
|
||||
if include_hidden_tables {
|
||||
true
|
||||
} else {
|
||||
!table.starts_with('_')
|
||||
}
|
||||
};
|
||||
|
||||
let database_name = if !is_sqlite {
|
||||
// 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
|
||||
@ -88,20 +110,9 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
);
|
||||
}
|
||||
|
||||
// Closures for filtering tables
|
||||
let filter_tables = |table: &str| -> bool {
|
||||
if !tables.is_empty() {
|
||||
return tables.contains(&table);
|
||||
}
|
||||
|
||||
true
|
||||
};
|
||||
let filter_hidden_tables = |table: &str| -> bool {
|
||||
if include_hidden_tables {
|
||||
true
|
||||
database_name
|
||||
} else {
|
||||
!table.starts_with('_')
|
||||
}
|
||||
Default::default()
|
||||
};
|
||||
|
||||
let table_stmts = match url.scheme() {
|
||||
@ -120,6 +131,21 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
.map(|schema| schema.write())
|
||||
.collect()
|
||||
}
|
||||
"sqlite" => {
|
||||
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;
|
||||
|
@ -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<TableStatement>) -> Result<EntityWriter, Error> {
|
||||
pub fn transform(table_create_stmts: Vec<TableCreateStatement>) -> Result<EntityWriter, Error> {
|
||||
let mut enums: HashMap<String, ActiveEnum> = HashMap::new();
|
||||
let mut inverse_relations: HashMap<String, Vec<Relation>> = HashMap::new();
|
||||
let mut conjunct_relations: HashMap<String, Vec<ConjunctRelation>> = 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<PrimaryKey> = Vec::new();
|
||||
let columns: Vec<Column> = 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,7 +103,8 @@ impl EntityTransformer {
|
||||
})
|
||||
.rev()
|
||||
.collect();
|
||||
let primary_keys = table_create
|
||||
primary_keys.extend(
|
||||
table_create
|
||||
.get_indexes()
|
||||
.iter()
|
||||
.filter(|index| index.is_primary_key())
|
||||
@ -111,8 +116,8 @@ impl EntityTransformer {
|
||||
.map(|name| PrimaryKey { name })
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
.flatten(),
|
||||
);
|
||||
let entity = Entity {
|
||||
table_name: table_name.clone(),
|
||||
columns,
|
||||
@ -180,9 +185,17 @@ impl EntityTransformer {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (tbl_name, mut relations) in inverse_relations.into_iter() {
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user