Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sea-orm-cli Implement derives & attributes parameters for entity generation #1124

Merged

Conversation

tsar-boomba
Copy link
Contributor

PR Info

Adds

Ability to add bonus derive macros and attributes to generated models.

Changes

Reusable testing utilities for codegen crate & tests for the new features added.

@tyt2y3 tyt2y3 requested a review from billy1624 October 23, 2022 13:49
@tsar-boomba
Copy link
Contributor Author

tsar-boomba commented Oct 26, 2022

Should this also add derives to active enums, realizing that they might need the traits derived too?

EDIT: I see this was changed in 0.10.0 and is no longer necessary.

Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

Hey @tsar-boomba, thanks for contributing!!

I have some suggested code changes: tsar-boomba#1
Please check and see if it make sense to you :)

@billy1624
Copy link
Member

Should this also add derives to active enums, realizing that they might need the traits derived too?

EDIT: I see this was changed in 0.10.0 and is no longer necessary.

I didn't catch it. Why adding custom derives to active enums is no longer necessary in 0.10.0?

@tsar-boomba
Copy link
Contributor Author

It seems that after 0.10, by default it produces this

#[sea_orm(column_type = "Custom(\"note_type\".to_owned())", nullable)]
pub r#type: Option<String>,

for a column with an enum type (Postgres). Before it would make a separate file called active_enum I believe.

@tsar-boomba
Copy link
Contributor Author

One other thing, the fully qualified name is being mangled when parsed into TokenStream.

Before parsing to TokenStream:
"ts_rs::TS"

After parsing to TokenStream (spaces added before and after "::"):
ts_rs :: TS

Any idea what is going on with this? The derives work as expected, so maybe this doesn't matter since they're generated files anyways.

@billy1624
Copy link
Member

It seems that after 0.10, by default it produces this

#[sea_orm(column_type = "Custom(\"note_type\".to_owned())", nullable)]
pub r#type: Option<String>,

for a column with an enum type (Postgres). Before it would make a separate file called active_enum I believe.

Oh, please install sea-orm-cli 0.10.1, this has been fixed on latest version.

@tsar-boomba
Copy link
Contributor Author

Alright, I've updated and see the enum is there. So should --derives be applied to enums or should there be a --active-enum-derives for only active enums, I'd prefer the latter. Also seeing "use of undeclared crate or module sea_query" error on the DeriveActiveEnum for the enum.

@billy1624 billy1624 changed the base branch from master to cli-derives-and-attribues December 20, 2022 03:33
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

Hey @tsar-boomba, sorry for the delay. I'd like to refactor it a bit. I'll merge it into a local branch before it was committed into master. Thanks again for the contributions!!

@billy1624 billy1624 merged commit b62243d into SeaQL:cli-derives-and-attribues Dec 20, 2022
billy1624 added a commit that referenced this pull request Dec 20, 2022
…y generation (#1321)

* sea-orm-cli Implement derives & attributes parameters for entity generation (#1124)

* implement derives & attributes for cli

* fmt and clippy fix

* use comma delimiter for attributes arg

* Update help message use `'` instead of `"` to quote

* Refactoring

* remove unnecessary cloning

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>

* [CLI] generate model with extra derives and attributes

* clippy

Co-authored-by: Isaiah Gamble <77396670+tsar-boomba@users.noreply.github.com>
@tsar-boomba tsar-boomba deleted the clie-derives-and-attribues branch December 20, 2022 08:35
tyt2y3 added a commit to SeaQL/seaql.github.io that referenced this pull request Feb 3, 2023
* Update 02-writing-migration.md

* Update SeaORM/docs/03-migration/02-writing-migration.md

* Support various UUID formats that are available in `uuid::fmt` module (SeaQL/sea-orm#1325)

* Casting columns as a different data type on select, insert and update (SeaQL/sea-orm#1304)

* Methods of `ActiveModelBehavior` receive db connection as a parameter (SeaQL/sea-orm#1145, SeaQL/sea-orm#1328)

* Added `execute_unprepared` method to `DatabaseConnection` and `DatabaseTransaction` (SeaQL/sea-orm#1327)

* Added `Select::into_tuple` to select rows as tuples (instead of defining a custom Model) (SeaQL/sea-orm#1311)

* Generate `#[serde(skip)]` for hidden columns (SeaQL/sea-orm#1171, SeaQL/sea-orm#1320)

* Generate entity with extra derives and attributes for model struct (SeaQL/sea-orm#1124, SeaQL/sea-orm#1321)

* Generate entity with extra derives and attributes for model struct (SeaQL/sea-orm#1124, SeaQL/sea-orm#1321)

* async_trait

* Migrations are now performed inside a transaction for Postgres (SeaQL/sea-orm#1379)

* `MockDatabase::append_exec_results()`, `MockDatabase::append_query_results()`, `MockDatabase::append_exec_errors()` and `MockDatabase::append_query_errors()` take any types implemented `IntoIterator` trait (SeaQL/sea-orm#1367)

* Cleanup the use of `vec!` macros

* Added `DatabaseConnection::close` (SeaQL/sea-orm#1236)

* Added `ActiveValue::reset` to convert `Unchanged` into `Set` (SeaQL/sea-orm#1177)

* Added `QueryTrait::apply_if` to optionally apply a filter (SeaQL/sea-orm#1415)

* Added the `sea-orm-internal` feature flag to expose some SQLx types (SeaQL/sea-orm#1297, SeaQL/sea-orm#1434)

* Add `QuerySelect::columns` method - select multiple columns (SeaQL/sea-orm#1264)

* Edit

* Update SeaORM/docs/02-install-and-config/02-connection.md

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>

* Update SeaORM/docs/05-basic-crud/03-insert.md

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>

* fmt

* Edit

---------

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

sea-orm-cli [Feature Request] Custom derives and attributes for entity generation
2 participants