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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theelderbeever
Copy link

@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

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.

None yet

1 participant