feat: add database entities models
This commit is contained in:
parent
19e9657ed8
commit
be0114601e
6 changed files with 123 additions and 0 deletions
9
model/Cargo.toml
Normal file
9
model/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "scct-model"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
sea-orm = { version = "0.12.15", features = ["runtime-tokio-rustls", "sqlx-mysql", "sqlx-sqlite", "sqlx-postgres"] }
|
25
model/src/chats.rs
Normal file
25
model/src/chats.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "chats")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::messages::Entity")]
|
||||
Messages,
|
||||
}
|
||||
|
||||
impl Related<super::messages::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Messages.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
6
model/src/lib.rs
Normal file
6
model/src/lib.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
pub mod chats;
|
||||
pub mod messages;
|
||||
pub mod users;
|
||||
|
||||
mod prelude;
|
||||
pub use prelude::*;
|
49
model/src/messages.rs
Normal file
49
model/src/messages.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "messages")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub chat_id: Uuid,
|
||||
pub content: Option<String>,
|
||||
pub created: ChronoDateTimeUtc,
|
||||
pub updated: Option<ChronoDateTimeUtc>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::chats::Entity",
|
||||
from = "Column::ChatId",
|
||||
to = "super::chats::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
Chats,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
Users,
|
||||
}
|
||||
|
||||
impl Related<super::chats::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Chats.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
3
model/src/prelude.rs
Normal file
3
model/src/prelude.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub use super::chats::Entity as Chats;
|
||||
pub use super::messages::Entity as Messages;
|
||||
pub use super::users::Entity as Users;
|
31
model/src/users.rs
Normal file
31
model/src/users.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub username: String,
|
||||
pub domain: String,
|
||||
pub display_name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub created: ChronoDateTimeUtc,
|
||||
pub updated: Option<ChronoDateTimeUtc>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::messages::Entity")]
|
||||
Messages,
|
||||
}
|
||||
|
||||
impl Related<super::messages::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Messages.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
Loading…
Reference in a new issue