Repository: diesel-rs/diesel
File: diesel/src/expression/case_when.rs (Rust)

Code before:
    /// See the [`case_when`] documentation for more details.
    pub fn when<C, T>(self, condition: C, if_true: T) -> helper_types::When<Self, C, T>
    where
        Self: CaseWhenTypesExtractor<Whens = Whens, Else = E>,
        C: Expression,
        <C as Expression>::SqlType: BoolOrNullableBool,
        T: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
    {
        CaseWhen {
            whens: CaseWhenConditionsIntermediateNode {
                first_whens: self.whens,
                last_when: CaseWhenConditionsLeaf {
                    when: Grouped(condition),
                    then: Grouped(if_true.as_expression()),
                },
            },
            else_expr: self.else_expr,
        }
    }
}

impl<Whens> CaseWhen<Whens, NoElseExpression> {
    /// Sets the `ELSE` branch of the `CASE` expression
    ///
    /// See the [`case_when`] documentation for more details.
    pub fn else_<E>(self, if_no_other_branch_matched: E) -> helper_types::Else_<Self, E>
    where
        Self: CaseWhenTypesExtractor<Whens = Whens, Else = NoElseExpression>,
        E: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
    {
        CaseWhen {
            whens: self.whens,
            else_expr: ElseExpression {
                expr: Grouped(if_no_other_branch_matched.as_expression()),
            },
        }
    }
}

pub(crate) use non_public_types::*;
mod non_public_types {
    use super::CaseWhen;

    use diesel_derives::{QueryId, ValidGrouping};

    use crate::expression::{
        AppearsOnTable, Expression, SelectableExpression, TypedExpressionType,
    };
    use crate::query_builder::{AstPass, QueryFragment};
    use crate::query_source::aliasing;
    use crate::sql_types::{BoolOrNullableBool, IntoNullable, SqlType};

Review comment (suggestion):
Let's call it `otherwise` instead of using `else_`.

Code after:
    /// See the [`case_when`] documentation for more details.
    pub fn when<C, T>(self, condition: C, if_true: T) -> helper_types::When<Self, C, T>
    where
        Self: CaseWhenTypesExtractor<Whens = Whens, Else = E>,
        C: Expression,
        <C as Expression>::SqlType: BoolOrNullableBool,
        T: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
    {
        CaseWhen {
            whens: CaseWhenConditionsIntermediateNode {
                first_whens: self.whens,
                last_when: CaseWhenConditionsLeaf {
                    when: Grouped(condition),
                    then: Grouped(if_true.as_expression()),
                },
            },
            else_expr: self.else_expr,
        }
    }
}

impl<Whens> CaseWhen<Whens, NoElseExpression> {
    /// Sets the `ELSE` branch of the `CASE` expression
    ///
    /// It is named this way because `else` is a reserved keyword in Rust
    ///
    /// See the [`case_when`] documentation for more details.
    pub fn otherwise<E>(self, if_no_other_branch_matched: E) -> helper_types::Otherwise<Self, E>
    where
        Self: CaseWhenTypesExtractor<Whens = Whens, Else = NoElseExpression>,
        E: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
    {
        CaseWhen {
            whens: self.whens,
            else_expr: ElseExpression {
                expr: Grouped(if_no_other_branch_matched.as_expression()),
            },
        }
    }
}

pub(crate) use non_public_types::*;
mod non_public_types {
    use super::CaseWhen;

    use diesel_derives::{QueryId, ValidGrouping};

    use crate::expression::{
        AppearsOnTable, Expression, SelectableExpression, TypedExpressionType,
    };
    use crate::query_builder::{AstPass, QueryFragment};