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

Rewrite enum and text casting #973

Merged
merged 3 commits into from
Sep 4, 2022
Merged

Rewrite enum and text casting #973

merged 3 commits into from
Sep 4, 2022

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Aug 15, 2022

PR Info

Adds

  • QuerySelect::column method also handle enum type

Changes

  • Refactor all enum and text casting in SeaORM

@billy1624 billy1624 self-assigned this Aug 15, 2022
@billy1624 billy1624 marked this pull request as ready for review August 16, 2022 07:45
@billy1624 billy1624 requested a review from tyt2y3 August 16, 2022 07:45
src/query/helper.rs Outdated Show resolved Hide resolved
fn cast_enum_text_inner<C, F>(expr: Expr, col: &C, f: F) -> SimpleExpr
where
C: ColumnTrait,
F: Fn(Expr, &String) -> SimpleExpr,
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I might have lost the context, but why are we passing enum name around as String? Can we pass around DynIden instead?

Copy link
Member Author

@billy1624 billy1624 Aug 24, 2022

Choose a reason for hiding this comment

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

The String comes from ColumnType::Enum

Enum(String, Vec<String>),

I rewrite it into F: Fn(Expr, DynIden) -> SimpleExpr, but still, we need to wrap the String as DynIden like SeaRc::new(Alias::new(enum_name))

Copy link
Member

@tyt2y3 tyt2y3 Sep 4, 2022

Choose a reason for hiding this comment

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

Um... I think we should have used an Iden here. Second question is, how often is this ColumnType object being cloned? If it is being cloned frequently then we'd better Arc it. At the very least I think a named struct serves as a better documentation:

EnumDef {
    name: DynIden,
    variants: Vec<DynIden>,
}

@billy1624 billy1624 requested a review from tyt2y3 August 24, 2022 08:54
@tyt2y3 tyt2y3 merged commit a80c33e into master Sep 4, 2022
@tyt2y3 tyt2y3 deleted the cast-between-enum-and-text branch September 4, 2022 16:38
tyt2y3 pushed a commit that referenced this pull request Sep 30, 2022
* Rewrite enum and text casting

* Add doc tests

* Refactoring
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.

fn column() also handle enum type
2 participants