mirror of https://github.com/JSH32/Backpack.git
47 lines
1.1 KiB
Rust
47 lines
1.1 KiB
Rust
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.1
|
|
|
|
use sea_orm::{entity::prelude::*, Set};
|
|
|
|
use super::DB_SONYFLAKE;
|
|
|
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
|
#[sea_orm(table_name = "files")]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key, auto_increment = false)]
|
|
pub id: String,
|
|
#[sea_orm(unique)]
|
|
pub name: String,
|
|
pub original_name: String,
|
|
pub uploader: String,
|
|
pub hash: String,
|
|
pub uploaded: DateTimeWithTimeZone,
|
|
pub size: i64,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
pub enum Relation {
|
|
#[sea_orm(
|
|
belongs_to = "super::users::Entity",
|
|
from = "Column::Uploader",
|
|
to = "super::users::Column::Id",
|
|
on_update = "NoAction",
|
|
on_delete = "Cascade"
|
|
)]
|
|
Users,
|
|
}
|
|
|
|
impl Related<super::users::Entity> for Entity {
|
|
fn to() -> RelationDef {
|
|
Relation::Users.def()
|
|
}
|
|
}
|
|
|
|
impl ActiveModelBehavior for ActiveModel {
|
|
fn new() -> Self {
|
|
Self {
|
|
id: Set(DB_SONYFLAKE.next_id().unwrap().to_string()),
|
|
..ActiveModelTrait::default()
|
|
}
|
|
}
|
|
}
|