bazzar/crates/model/src/v4/customers.rs
2023-06-03 13:31:57 +02:00

139 lines
3.7 KiB
Rust

//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"customers"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq, Serialize, Deserialize)]
pub struct Model {
pub id: String,
pub email: String,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub billing_address_id: Option<String>,
pub password_hash: Option<String>,
pub phone: Option<String>,
pub has_account: bool,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub deleted_at: Option<DateTimeWithTimeZone>,
pub metadata: Option<Json>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Email,
FirstName,
LastName,
BillingAddressId,
PasswordHash,
Phone,
HasAccount,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = String;
fn auto_increment() -> bool {
false
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
Addresses,
Carts,
Notifications,
Orders,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::String(None).def(),
Self::Email => ColumnType::String(None).def(),
Self::FirstName => ColumnType::String(None).def().null(),
Self::LastName => ColumnType::String(None).def().null(),
Self::BillingAddressId => ColumnType::String(None).def().null().unique(),
Self::PasswordHash => ColumnType::String(None).def().null(),
Self::Phone => ColumnType::String(None).def().null(),
Self::HasAccount => ColumnType::Boolean.def(),
Self::CreatedAt => ColumnType::TimestampWithTimeZone.def(),
Self::UpdatedAt => ColumnType::TimestampWithTimeZone.def(),
Self::DeletedAt => ColumnType::TimestampWithTimeZone.def().null(),
Self::Metadata => ColumnType::JsonBinary.def().null(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Addresses => Entity::belongs_to(super::addresses::Entity)
.from(Column::BillingAddressId)
.to(super::addresses::Column::Id)
.into(),
Self::Carts => Entity::has_many(super::carts::Entity).into(),
Self::Notifications => Entity::has_many(super::notifications::Entity).into(),
Self::Orders => Entity::has_many(super::orders::Entity).into(),
}
}
}
impl Related<super::addresses::Entity> for Entity {
fn to() -> RelationDef {
Relation::Addresses.def()
}
}
impl Related<super::carts::Entity> for Entity {
fn to() -> RelationDef {
Relation::Carts.def()
}
}
impl Related<super::notifications::Entity> for Entity {
fn to() -> RelationDef {
Relation::Notifications.def()
}
}
impl Related<super::orders::Entity> for Entity {
fn to() -> RelationDef {
Relation::Orders.def()
}
}
impl Related<super::customer_groups::Entity> for Entity {
fn to() -> RelationDef {
super::customer_group_customers::Relation::CustomerGroups.def()
}
fn via() -> Option<RelationDef> {
Some(
super::customer_group_customers::Relation::Customers
.def()
.rev(),
)
}
}
impl ActiveModelBehavior for ActiveModel {}