diff --git a/model/Cargo.toml b/model/Cargo.toml new file mode 100644 index 0000000..67d8bee --- /dev/null +++ b/model/Cargo.toml @@ -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"] } diff --git a/model/src/chats.rs b/model/src/chats.rs new file mode 100644 index 0000000..be43e7d --- /dev/null +++ b/model/src/chats.rs @@ -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 for Entity { + fn to() -> RelationDef { + Relation::Messages.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/model/src/lib.rs b/model/src/lib.rs new file mode 100644 index 0000000..7cc3f93 --- /dev/null +++ b/model/src/lib.rs @@ -0,0 +1,6 @@ +pub mod chats; +pub mod messages; +pub mod users; + +mod prelude; +pub use prelude::*; diff --git a/model/src/messages.rs b/model/src/messages.rs new file mode 100644 index 0000000..cc04043 --- /dev/null +++ b/model/src/messages.rs @@ -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, + pub created: ChronoDateTimeUtc, + pub updated: Option, +} + +#[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 for Entity { + fn to() -> RelationDef { + Relation::Chats.def() + } +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Users.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/model/src/prelude.rs b/model/src/prelude.rs new file mode 100644 index 0000000..408d2c2 --- /dev/null +++ b/model/src/prelude.rs @@ -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; diff --git a/model/src/users.rs b/model/src/users.rs new file mode 100644 index 0000000..1a9ba16 --- /dev/null +++ b/model/src/users.rs @@ -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, + pub description: Option, + pub avatar: Option, + pub created: ChronoDateTimeUtc, + pub updated: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm(has_many = "super::messages::Entity")] + Messages, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::Messages.def() + } +} + +impl ActiveModelBehavior for ActiveModel {}