~eviee/yapweb

be337206a7bea5b5b06f00f571b406e6a3f2ebc3 — Evie Viau 2 years ago 5843ad9 main
Generate entities
A src/entities/mod.rs => src/entities/mod.rs +7 -0
@@ 0,0 1,7 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

pub mod prelude;

pub mod package;
pub mod ssh_key;
pub mod user;

A src/entities/package.rs => src/entities/package.rs +41 -0
@@ 0,0 1,41 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "package")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: String,
    pub name: String,
    pub version: String,
    pub epoch: i32,
    pub description: String,
    pub url: String,
    pub licenses: Vec<String>,
    pub depends: Option<Vec<String>>,
    pub optional_depends: Option<Vec<String>>,
    pub make_depends: Option<Vec<String>>,
    pub provides: Vec<String>,
    pub owner: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::user::Entity",
        from = "Column::Owner",
        to = "super::user::Column::Id",
        on_update = "NoAction",
        on_delete = "NoAction"
    )]
    User,
}

impl Related<super::user::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::User.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}

A src/entities/prelude.rs => src/entities/prelude.rs +5 -0
@@ 0,0 1,5 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

pub use super::package::Entity as Package;
pub use super::ssh_key::Entity as SshKey;
pub use super::user::Entity as User;

A src/entities/ssh_key.rs => src/entities/ssh_key.rs +33 -0
@@ 0,0 1,33 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "ssh_key")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: String,
    pub owner: String,
    pub name: String,
    pub key: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::user::Entity",
        from = "Column::Owner",
        to = "super::user::Column::Id",
        on_update = "NoAction",
        on_delete = "NoAction"
    )]
    User,
}

impl Related<super::user::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::User.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}

A src/entities/user.rs => src/entities/user.rs +41 -0
@@ 0,0 1,41 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

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 r#mod: bool,
    pub active: bool,
    pub display_name: String,
    #[sea_orm(unique)]
    pub email: String,
    pub password: String,
    pub homepage: Option<String>,
    pub language: String,
    pub timezone: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(has_many = "super::ssh_key::Entity")]
    SshKey,
    #[sea_orm(has_many = "super::package::Entity")]
    Package,
}

impl Related<super::ssh_key::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::SshKey.def()
    }
}

impl Related<super::package::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Package.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}

M src/main.rs => src/main.rs +1 -0
@@ 7,6 7,7 @@ use std::{net::SocketAddr, env};

mod api;
mod pages;
mod entities;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");