+
Skip to content

Conversation

billy1624
Copy link
Member

Run CLI generate entity command to generate entity files for frontend data:

cargo r -- generate entity --database-url postgres://root:root@localhost/database --frontend-format

Sample entity files:

use super::sea_orm_active_enums::Tea;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Model {
    pub id: i32,
    pub parent_id: i32,
    pub category: Option<String>,
    pub color: Option<i32>,
    pub tea: Option<Tea>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Tea {
    EverydayTea,
    BreakfastTea,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Model {
    pub id: i32,
    pub action: String,
    pub json: Json,
    pub created_at: DateTimeWithTimeZone,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Model {
    pub uuid: Uuid,
    pub r#type: String,
    pub key: String,
    pub value: String,
    pub bytes: Vec<u8>,
    pub date: Option<Date>,
    pub time: Option<Time>,
}
pub use super::active_enum::Model as ActiveEnum;
pub use super::active_enum_child::Model as ActiveEnumChild;
pub use super::applog::Model as Applog;
pub use super::binary::Model as Binary;
pub use super::bits::Model as Bits;
pub use super::byte_primary_key::Model as BytePrimaryKey;
pub use super::categories::Model as Categories;
pub use super::collection::Model as Collection;
pub use super::dyn_table_name_lazy_static_1::Model as DynTableNameLazyStatic1;
pub use super::dyn_table_name_lazy_static_2::Model as DynTableNameLazyStatic2;
pub use super::edit_log::Model as EditLog;
pub use super::event_trigger::Model as EventTrigger;
pub use super::host_network::Model as HostNetwork;
pub use super::insert_default::Model as InsertDefault;
pub use super::json_string_vec::Model as JsonStringVec;
pub use super::json_struct::Model as JsonStruct;
pub use super::json_struct_vec::Model as JsonStructVec;
pub use super::json_vec::Model as JsonVec;
pub use super::metadata::Model as Metadata;
pub use super::pi::Model as Pi;
pub use super::repository::Model as Repository;
pub use super::satellite::Model as Satellite;
pub use super::self_join::Model as SelfJoin;
pub use super::teas::Model as Teas;
pub use super::transaction_log::Model as TransactionLog;
pub use super::uuid_fmt::Model as UuidFmt;
pub use super::value_type::Model as ValueType;
pub use super::value_type_postgres::Model as ValueTypePostgres;

@billy1624 billy1624 requested a review from tyt2y3 June 20, 2025 12:52
@billy1624 billy1624 self-assigned this Jun 20, 2025
@Expurple
Copy link
Member

Expurple commented Jun 20, 2025

Closes #648, #2622

Copy link
Member

@Expurple Expurple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks. This is a good first solution.

It doesn't provide ActiveModels, but that would require us to somehow extract ActiveValue from sea_orm into a separate crate that can compile on the frontend. We can figure that out later if there's demand for that.

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 23, 2025

somehow extract ActiveValue from sea_orm into a separate crate

I think the problem was serde does not natively distinguish between a missing field vs a null field. so custom serde impl is needed if we want to use Option<Option<T>>

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 23, 2025

I think we can backport this to 1.x

@tyt2y3 tyt2y3 merged commit 26b9716 into master Jun 23, 2025
64 of 72 checks passed
@tyt2y3 tyt2y3 deleted the ci-codegen-frontend branch June 23, 2025 10:57
@Expurple
Copy link
Member

if we want to use Option<Option<T>>

We can also (de)serialize ActiveValue as an explicit tagged enum. That's necessary, if we want to represent the difference between Set and Unchanged. But I'd wait for the actual use cases to see whether anyone needs this

tyt2y3 pushed a commit that referenced this pull request Jun 29, 2025
* codegen: frontend format

* codegen: prelude for frontend models

* rustfmt

* Fix ActiveEnum
Copy link

🎉 Released In 1.1.13 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

@SeaQL SeaQL deleted a comment from github-actions bot Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载