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

feat: Add .apply_if to SelectStatement #800

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

theelderbeever
Copy link
Contributor

@theelderbeever theelderbeever commented Aug 6, 2024

PR Info

The .apply_if method from SeaORM is πŸ‘¨β€πŸ³ πŸ’‹ in my opinion. This PR adds a similar method to the SelectStatement that can live beside .conditions as a more direct way to unpack Option type conditionals.

let query = Query::select()
    .column(Char::Character)
    .from(Char::Table)
    .apply_if(
        Some(5),
        |q, v| {
            q.and_where(Expr::col(Char::FontId).eq(v));
        }
    )
    .to_owned();

New Features

  • Adds convenience function pub fn apply_if<T, F>(&mut self, val: Option<T>, if_some: F) to SelectStatement in an attempt to emulate SeaORM's .apply_if functionality.

Bug Fixes

N/A

Breaking Changes

N/A

Changes

  • Adds corresponding doctest

Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

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

Thank you!

@theelderbeever
Copy link
Contributor Author

@tyt2y3 Saw the doctest failed on formatting so just pushed the fix.

@tyt2y3 tyt2y3 merged commit 1928f23 into SeaQL:master Aug 15, 2024
20 checks passed
tyt2y3 pushed a commit that referenced this pull request Aug 20, 2024
* feat: Add .apply_if to SelectStatement

* fix: Satisfy cargo fmt in doctest
This pull request was closed.
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.

2 participants