Elimina la excesiva rigidez que impone SeaORM
This commit is contained in:
parent
d07611d044
commit
13c2e77688
7 changed files with 0 additions and 166 deletions
|
|
@ -14,5 +14,4 @@ repository = "https://gitlab.com/manuelcillero/pagetop"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pagetop = { path = "../pagetop" }
|
pagetop = { path = "../pagetop" }
|
||||||
sea-orm = { version = "0.7.1" }
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
pub mod role;
|
|
||||||
pub mod role_permission;
|
|
||||||
pub mod user;
|
|
||||||
pub mod user_role;
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
use pagetop::db::entity::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "role")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub rid : u32,
|
|
||||||
#[sea_orm(unique)]
|
|
||||||
pub name : String,
|
|
||||||
#[sea_orm(default_value = 0)]
|
|
||||||
pub weight: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
||||||
pub enum Relation {
|
|
||||||
RolePermission,
|
|
||||||
UserRole,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelationTrait for Relation {
|
|
||||||
fn def(&self) -> RelationDef {
|
|
||||||
match self {
|
|
||||||
Self::RolePermission => Entity::has_many(super::role_permission::Entity).into(),
|
|
||||||
Self::UserRole => Entity::has_many(super::user_role::Entity).into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::role_permission::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::RolePermission.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::user_role::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::UserRole.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
use pagetop::db::entity::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "role_permission")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub rid : u32,
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub permission: String,
|
|
||||||
pub module : String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
||||||
pub enum Relation {
|
|
||||||
Role,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelationTrait for Relation {
|
|
||||||
fn def(&self) -> RelationDef {
|
|
||||||
match self {
|
|
||||||
Self::Role => Entity::belongs_to(super::role::Entity)
|
|
||||||
.from(Column::Rid)
|
|
||||||
.to(super::role::Column::Rid)
|
|
||||||
.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::role::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Role.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
use pagetop::db::entity::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "user")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub uid : u32,
|
|
||||||
#[sea_orm(unique)]
|
|
||||||
pub name : String,
|
|
||||||
pub pass : String,
|
|
||||||
pub mail : Option<String>,
|
|
||||||
pub created : DateTimeUtc,
|
|
||||||
pub changed : DateTimeUtc,
|
|
||||||
pub access : DateTimeUtc,
|
|
||||||
pub login : DateTimeUtc,
|
|
||||||
pub status : bool,
|
|
||||||
pub timezone: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
||||||
pub enum Relation {
|
|
||||||
UserRole,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelationTrait for Relation {
|
|
||||||
fn def(&self) -> RelationDef {
|
|
||||||
match self {
|
|
||||||
Self::UserRole => Entity::has_many(super::user_role::Entity).into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::user_role::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::UserRole.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
use pagetop::db::entity::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "user_role")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub uid: u32,
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub rid: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
|
||||||
pub enum Relation {
|
|
||||||
User,
|
|
||||||
Role,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RelationTrait for Relation {
|
|
||||||
fn def(&self) -> RelationDef {
|
|
||||||
match self {
|
|
||||||
Self::User => Entity::belongs_to(super::user::Entity)
|
|
||||||
.from(Column::Uid)
|
|
||||||
.to(super::user::Column::Uid)
|
|
||||||
.into(),
|
|
||||||
Self::Role => Entity::belongs_to(super::role::Entity)
|
|
||||||
.from(Column::Rid)
|
|
||||||
.to(super::role::Column::Rid)
|
|
||||||
.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::user::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::User.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Related<super::role::Entity> for Entity {
|
|
||||||
fn to() -> RelationDef {
|
|
||||||
Relation::Role.def()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -2,7 +2,6 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
localize!("src/locales");
|
localize!("src/locales");
|
||||||
|
|
||||||
mod entity;
|
|
||||||
mod migration;
|
mod migration;
|
||||||
|
|
||||||
pub struct UserModule;
|
pub struct UserModule;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue