Move to new design

This commit is contained in:
eraden 2023-07-26 21:49:37 +02:00
parent 29f8a421c4
commit d48b39c5c3
2 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,82 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use sea_orm::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"parking_space_rents"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)]
pub struct Model {
pub id: i32,
pub price: i32,
pub parking_space_id: i32,
pub available: bool,
pub created_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Price,
ParkingSpaceId,
Available,
CreatedAt,
UpdatedAt,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
ParkingSpaces,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Price => ColumnType::Integer.def(),
Self::ParkingSpaceId => ColumnType::Integer.def(),
Self::Available => ColumnType::Boolean.def(),
Self::CreatedAt => ColumnType::DateTime.def(),
Self::UpdatedAt => ColumnType::DateTime.def(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::ParkingSpaces => Entity::belongs_to(super::parking_spaces::Entity)
.from(Column::ParkingSpaceId)
.to(super::parking_spaces::Column::Id)
.into(),
}
}
}
impl Related<super::parking_spaces::Entity> for Entity {
fn to() -> RelationDef {
Relation::ParkingSpaces.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -0,0 +1,92 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use sea_orm::entity::prelude::*;
use super::sea_orm_active_enums::ParkingSpaceState;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"parking_spaces"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)]
pub struct Model {
pub id: i32,
pub state: ParkingSpaceState,
pub location: String,
pub account_id: i32,
pub created_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
State,
Location,
AccountId,
CreatedAt,
UpdatedAt,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
Accounts,
ParkingSpaceRents,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::State => ParkingSpaceState::db_type(),
Self::Location => ColumnType::String(None).def(),
Self::AccountId => ColumnType::Integer.def(),
Self::CreatedAt => ColumnType::DateTime.def(),
Self::UpdatedAt => ColumnType::DateTime.def(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Accounts => Entity::belongs_to(super::accounts::Entity)
.from(Column::AccountId)
.to(super::accounts::Column::Id)
.into(),
Self::ParkingSpaceRents => Entity::has_many(super::parking_space_rents::Entity).into(),
}
}
}
impl Related<super::accounts::Entity> for Entity {
fn to() -> RelationDef {
Relation::Accounts.def()
}
}
impl Related<super::parking_space_rents::Entity> for Entity {
fn to() -> RelationDef {
Relation::ParkingSpaceRents.def()
}
}
impl ActiveModelBehavior for ActiveModel {}