feat(codgen): Allow hiding SeaORM specific traits behind features#2988
Draft
AaronDewes wants to merge 4 commits intoSeaQL:masterfrom
Draft
feat(codgen): Allow hiding SeaORM specific traits behind features#2988AaronDewes wants to merge 4 commits intoSeaQL:masterfrom
AaronDewes wants to merge 4 commits intoSeaQL:masterfrom
Conversation
a18d6a1 to
3a1d4fb
Compare
48c23ce to
a311708
Compare
Member
|
interesting, can you give an example what the generated entity looks like? |
Author
Here's an example from a project where I'm using this with Leptos ( //! `SeaORM` Entity, @generated by sea-orm-codegen 2.0
#[cfg(feature = "ssr")]
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "ssr", derive(DeriveEntityModel))]
#[cfg_attr(feature = "ssr", sea_orm(table_name = "teams"))]
pub struct Model {
#[cfg_attr(feature = "ssr", sea_orm(primary_key))]
pub id: i32,
pub name: String,
pub org_id: i32,
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "ssr", derive(EnumIter, DeriveRelation))]
pub enum Relation {
#[cfg_attr(feature = "ssr", sea_orm(has_many = "super::apps::Entity"))]
Apps,
#[cfg_attr(
feature = "ssr",
sea_orm(
belongs_to = "super::organizations::Entity",
from = "Column::OrgId",
to = "super::organizations::Column::Id",
on_update = "NoAction",
on_delete = "Cascade",
)
)]
Organizations,
#[cfg_attr(feature = "ssr", sea_orm(has_many = "super::team_memberships::Entity"))]
TeamMemberships,
}
#[cfg(feature = "ssr")]
impl Related<super::apps::Entity> for Entity {
fn to() -> RelationDef {
Relation::Apps.def()
}
}
#[cfg(feature = "ssr")]
impl Related<super::organizations::Entity> for Entity {
fn to() -> RelationDef {
Relation::Organizations.def()
}
}
#[cfg(feature = "ssr")]
impl Related<super::team_memberships::Entity> for Entity {
fn to() -> RelationDef {
Relation::TeamMemberships.def()
}
}
#[cfg(feature = "ssr")]
#[cfg(feature = "ssr")]
impl ActiveModelBehavior for ActiveModel {}(This is the compact format, I will fix the duplicate cfg in the last block later) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes it possible to set a
--sea-orm-featureflag that makes generated code not depend onsea-ormunless that feature is enabled.This allows having just one set of generated files that can be used on frontend and backend for shared types. The
--frontend-formatflag previously required creating different files.This PR currently lacks tests. Before creating tests, I wanted to open this draft to see if this is even a feature you want or if it's something you wouldn't merge anyway.
PR Info
New Features
Bug Fixes
None
Breaking Changes
None
Changes
None