fn insensitive_scalar_filter(field: &ScalarFieldRef, condition: ScalarCondition) -> crate::Result<Document> {
    Ok(match condition {
        ScalarCondition::Equals(val) => doc! { "$regex": to_regex(field, "^", val, "$", true)? },
        ScalarCondition::NotEquals(val) => {
            doc! { "$not": { "$regex": to_regex(field, "^", val, "$", true)? }}
        }

        ScalarCondition::Contains(val) => doc! { "$regex": to_regex(field, ".*", val, ".*", true)? },
        ScalarCondition::NotContains(val) => doc! { "$not": { "$regex": to_regex(field, ".*", val, ".*", true)? }},
        ScalarCondition::StartsWith(val) => doc! { "$regex": to_regex(field, "^", val, "", true)?  },
        ScalarCondition::NotStartsWith(val) => doc! { "$not": { "$regex": to_regex(field, "^", val, "", true)? }},
        ScalarCondition::EndsWith(val) => doc! { "$regex": to_regex(field, "", val, "$", true)? },
        ScalarCondition::NotEndsWith(val) => doc! { "$not": { "$regex": to_regex(field, "", val, "$", true)? }},
        ScalarCondition::LessThan(val) => doc! { "$lt": (field, val).into_bson()? },
        ScalarCondition::LessThanOrEquals(val) => doc! { "$lte": (field, val).into_bson()? },
        ScalarCondition::GreaterThan(val) => doc! { "$gt": (field, val).into_bson()? },
        ScalarCondition::GreaterThanOrEquals(val) => doc! { "$gte": (field, val).into_bson()? },
        // Todo: The nested list unpack looks like a bug somewhere.
        //       Likely join code mistakenly repacks a list into a list of PrismaValue somewhere in the core.
        ScalarCondition::In(vals) => match vals.split_first() {
            // List is list of lists, we need to flatten.
            Some((PrismaValue::List(_), _)) => {
                let mut bson_values = Vec::with_capacity(vals.len());

                for pv in vals {
                    if let PrismaValue::List(inner) = pv {
                        bson_values.extend(to_regex_list(field, "^", inner, "$", true)?)
                    }
                }

                doc! { "$in": bson_values }
            }

            _ => doc! { "$in": to_regex_list(field, "^", vals, "$", true)? },
        },
        ScalarCondition::NotIn(vals) => {
            doc! { "$nin": to_regex_list(field, "^", vals, "$", true)? }
        }
        ScalarCondition::JsonCompare(_) => unimplemented!("JSON filtering is not yet supported on MongoDB"),
    })
}
/// Insensitive filters are only reachable with TypeIdentifier::String (or UUID, which is string as well for us).
Insensitive filters are only reachable with TypeIdentifier::String (or UUID, which is string as well for us).
Insensitive filters are only reachable with TypeIdentifier :: String ( or UUID which is string as well for us ) .
fn insensitive_scalar_filter(field: &ScalarFieldRef, condition: ScalarCondition) -> crate::Result<Document> {
    Ok(match condition {
        ScalarCondition::Equals(val) => doc! { "$regex": to_regex(field, "^", val, "$", true)? },
        ScalarCondition::NotEquals(val) => {
            doc! { "$not": { "$regex": to_regex(field, "^", val, "$", true)? }}
        }
        ScalarCondition::Contains(val) => doc! { "$regex": to_regex(field, ".*", val, ".*", true)? },
        ScalarCondition::NotContains(val) => doc! { "$not": { "$regex": to_regex(field, ".*", val, ".*", true)? }},
        ScalarCondition::StartsWith(val) => doc! { "$regex": to_regex(field, "^", val, "", true)?  },
        ScalarCondition::NotStartsWith(val) => doc! { "$not": { "$regex": to_regex(field, "^", val, "", true)? }},
        ScalarCondition::EndsWith(val) => doc! { "$regex": to_regex(field, "", val, "$", true)? },
        ScalarCondition::NotEndsWith(val) => doc! { "$not": { "$regex": to_regex(field, "", val, "$", true)? }},
        ScalarCondition::LessThan(val) => doc! { "$lt": (field, val).into_bson()? },
        ScalarCondition::LessThanOrEquals(val) => doc! { "$lte": (field, val).into_bson()? },
        ScalarCondition::GreaterThan(val) => doc! { "$gt": (field, val).into_bson()? },
        ScalarCondition::GreaterThanOrEquals(val) => doc! { "$gte": (field, val).into_bson()? },
        // Todo: The nested list unpack looks like a bug somewhere.
        //       Likely join code mistakenly repacks a list into a list of PrismaValue somewhere in the core.
        ScalarCondition::In(vals) => match vals.split_first() {
            // List is list of lists, we need to flatten.
            Some((PrismaValue::List(_), _)) => {
                let mut bson_values = Vec::with_capacity(vals.len());
                for pv in vals {
                    if let PrismaValue::List(inner) = pv {
                        bson_values.extend(to_regex_list(field, "^", inner, "$", true)?)
                    }
                }
                doc! { "$in": bson_values }
            }
            _ => doc! { "$in": to_regex_list(field, "^", vals, "$", true)? },
        },
        ScalarCondition::NotIn(vals) => {
            doc! { "$nin": to_regex_list(field, "^", vals, "$", true)? }
        }
        ScalarCondition::JsonCompare(_) => unimplemented!("JSON filtering is not yet supported on MongoDB"),
    })
}
fn insensitive_scalar_filter ( field : & ScalarFieldRef , condition : ScalarCondition ) -> crate :: Result < Document > { Ok ( match condition { ScalarCondition :: Equals ( val ) => doc ! { " " to_regex ( field " " val " " true ) } , ScalarCondition :: NotEquals ( val ) => { doc ! { " " { " " to_regex ( field " " val " " true ) } } } ScalarCondition :: Contains ( val ) => doc ! { " " to_regex ( field " " val " " true ) } , ScalarCondition :: NotContains ( val ) => doc ! { " " { " " to_regex ( field " " val " " true ) } } , ScalarCondition :: StartsWith ( val ) => doc ! { " " to_regex ( field " " val " " true ) } , ScalarCondition :: NotStartsWith ( val ) => doc ! { " " { " " to_regex ( field " " val " " true ) } } , ScalarCondition :: EndsWith ( val ) => doc ! { " " to_regex ( field " " val " " true ) } , ScalarCondition :: NotEndsWith ( val ) => doc ! { " " { " " to_regex ( field " " val " " true ) } } , ScalarCondition :: LessThan ( val ) => doc ! { " " ( field val ) into_bson ( ) } , ScalarCondition :: LessThanOrEquals ( val ) => doc ! { " " ( field val ) into_bson ( ) } , ScalarCondition :: GreaterThan ( val ) => doc ! { " " ( field val ) into_bson ( ) } , ScalarCondition :: GreaterThanOrEquals ( val ) => doc ! { " " ( field val ) into_bson ( ) } , // Todo: The nested list unpack looks like a bug somewhere. //       Likely join code mistakenly repacks a list into a list of PrismaValue somewhere in the core. ScalarCondition :: In ( vals ) => match vals . split_first ( ) { // List is list of lists, we need to flatten. Some ( ( PrismaValue :: List ( _ ) , _ ) ) => { let mut bson_values = Vec :: with_capacity ( vals . len ( ) ) ; for pv in vals { if let PrismaValue :: List ( inner ) = pv { bson_values . extend ( to_regex_list ( field , " " , inner , " " , true ) ? ) } } doc ! { " " bson_values } } _ => doc ! { " " to_regex_list ( field " " vals " " true ) } , } , ScalarCondition :: NotIn ( vals ) => { doc ! { " " to_regex_list ( field " " vals " " true ) } } ScalarCondition :: JsonCompare ( _ ) => unimplemented ! ( " " ) , } ) }
Insensitive filters are only reachable with TypeIdentifier::String (or UUID, which is string as well for us).
Insensitive filters are only reachable with TypeIdentifier :: String ( or UUID which is string as well for us ) .
field
&ScalarFieldRef
condition
ScalarCondition