[feat] first entities

This commit is contained in:
aprilthepink 2024-04-18 02:07:19 +02:00
parent ff728ef6f3
commit 8469b236a7
7 changed files with 431 additions and 143 deletions

6
src/entities/mod.rs Normal file
View file

@ -0,0 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
pub mod prelude;
pub mod post;
pub mod user;

68
src/entities/post.rs Normal file
View file

@ -0,0 +1,68 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "post")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub title: Option<String>,
pub content: String,
pub local: bool,
pub created_at: String,
pub updated_at: Option<String>,
pub reblog_id: Option<String>,
pub content_type: String,
pub visibility: String,
pub reply_id: Option<String>,
pub quoting_id: Option<String>,
pub sensitive: bool,
pub spoiler_text: Option<String>,
pub creator: String,
pub url: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "Entity",
from = "Column::QuotingId",
to = "Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
SelfRef3,
#[sea_orm(
belongs_to = "Entity",
from = "Column::ReplyId",
to = "Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
SelfRef2,
#[sea_orm(
belongs_to = "Entity",
from = "Column::ReblogId",
to = "Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
SelfRef1,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::Creator",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
User,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

4
src/entities/prelude.rs Normal file
View file

@ -0,0 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
pub use super::post::Entity as Post;
pub use super::user::Entity as User;

39
src/entities/user.rs Normal file
View file

@ -0,0 +1,39 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "user")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub username: String,
pub name: String,
pub summary: Option<String>,
pub url: String,
pub public_key: String,
pub private_key: Option<String>,
pub last_refreshed_at: String,
pub local: bool,
pub follower_count: i32,
pub following_count: i32,
pub created_at: String,
pub updated_at: Option<String>,
pub following: Option<String>,
pub followers: Option<String>,
pub inbox: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::post::Entity")]
Post,
}
impl Related<super::post::Entity> for Entity {
fn to() -> RelationDef {
Relation::Post.def()
}
}
impl ActiveModelBehavior for ActiveModel {}