fn default_scalar_filter(field: &ScalarFieldRef, condition: ScalarCondition) -> crate::Result<Document> {
    Ok(match condition {
        ScalarCondition::Equals(val) => doc! { "$eq": (field, val).into_bson()? },
        ScalarCondition::NotEquals(val) => doc! { "$ne": (field, val).into_bson()? },
        ScalarCondition::Contains(val) => doc! { "$regex": to_regex(field, ".*", val, ".*", false)? },
        ScalarCondition::NotContains(val) => doc! { "$not": { "$regex": to_regex(field, ".*", val, ".*", false)? }},
        ScalarCondition::StartsWith(val) => doc! { "$regex": to_regex(field, "^", val, "", false)? },
        ScalarCondition::NotStartsWith(val) => doc! { "$not": { "$regex": to_regex(field, "^", val, "", false)? }},
        ScalarCondition::EndsWith(val) => doc! { "$regex": to_regex(field, "", val, "$", false)? },
        ScalarCondition::NotEndsWith(val) => doc! { "$not": { "$regex": to_regex(field, "", val, "$", false)? }},
        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(
                            inner
                                .into_iter()
                                .map(|val| (field, val).into_bson())
                                .collect::<crate::Result<Vec<_>>>()?,
                        )
                    }
                }

                doc! { "$in": bson_values }
            }
            _ => doc! { "$in": (field, PrismaValue::List(vals)).into_bson()? },
        },
        ScalarCondition::NotIn(vals) => {
            doc! { "$nin": vals.into_iter().map(|val| (field, val).into_bson()).collect::<crate::Result<Vec<_>>>()? }
        }
        ScalarCondition::JsonCompare(jc) => match *jc.condition {
            ScalarCondition::Equals(value) => {
                let bson = (field, value).into_bson()?;
                doc! { "$eq": bson }
            }
            ScalarCondition::NotEquals(value) => {
                let bson = (field, value).into_bson()?;
                doc! { "$ne": bson }
            }
            _ => unimplemented!("Only equality JSON filtering is supported on MongoDB."),
        },
    })
}
// Note contains / startsWith / endsWith are only applicable to String types in the schema.
Note contains / startsWith / endsWith are only applicable to String types in the schema.
Note contains / startsWith / endsWith are only applicable to String types in the schema .
fn default_scalar_filter(field: &ScalarFieldRef, condition: ScalarCondition) -> crate::Result<Document> {
    Ok(match condition {
        ScalarCondition::Equals(val) => doc! { "$eq": (field, val).into_bson()? },
        ScalarCondition::NotEquals(val) => doc! { "$ne": (field, val).into_bson()? },
        ScalarCondition::Contains(val) => doc! { "$regex": to_regex(field, ".*", val, ".*", false)? },
        ScalarCondition::NotContains(val) => doc! { "$not": { "$regex": to_regex(field, ".*", val, ".*", false)? }},
        ScalarCondition::StartsWith(val) => doc! { "$regex": to_regex(field, "^", val, "", false)? },
        ScalarCondition::NotStartsWith(val) => doc! { "$not": { "$regex": to_regex(field, "^", val, "", false)? }},
        ScalarCondition::EndsWith(val) => doc! { "$regex": to_regex(field, "", val, "$", false)? },
        ScalarCondition::NotEndsWith(val) => doc! { "$not": { "$regex": to_regex(field, "", val, "$", false)? }},
        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(
                            inner
                                .into_iter()
                                .map(|val| (field, val).into_bson())
                                .collect::<crate::Result<Vec<_>>>()?,
                        )
                    }
                }
                doc! { "$in": bson_values }
            }
            _ => doc! { "$in": (field, PrismaValue::List(vals)).into_bson()? },
        },
        ScalarCondition::NotIn(vals) => {
            doc! { "$nin": vals.into_iter().map(|val| (field, val).into_bson()).collect::<crate::Result<Vec<_>>>()? }
        }
        ScalarCondition::JsonCompare(jc) => match *jc.condition {
            ScalarCondition::Equals(value) => {
                let bson = (field, value).into_bson()?;
                doc! { "$eq": bson }
            }
            ScalarCondition::NotEquals(value) => {
                let bson = (field, value).into_bson()?;
                doc! { "$ne": bson }
            }
            _ => unimplemented!("Only equality JSON filtering is supported on MongoDB."),
        },
    })
}
fn default_scalar_filter ( field : & ScalarFieldRef , condition : ScalarCondition ) -> crate :: Result < Document > { Ok ( match condition { ScalarCondition :: Equals ( val ) => doc ! { " " ( field val ) into_bson ( ) } , ScalarCondition :: NotEquals ( val ) => doc ! { " " ( field val ) into_bson ( ) } , ScalarCondition :: Contains ( val ) => doc ! { " " to_regex ( field " " val " " false ) } , ScalarCondition :: NotContains ( val ) => doc ! { " " { " " to_regex ( field " " val " " false ) } } , ScalarCondition :: StartsWith ( val ) => doc ! { " " to_regex ( field " " val " " false ) } , ScalarCondition :: NotStartsWith ( val ) => doc ! { " " { " " to_regex ( field " " val " " false ) } } , ScalarCondition :: EndsWith ( val ) => doc ! { " " to_regex ( field " " val " " false ) } , ScalarCondition :: NotEndsWith ( val ) => doc ! { " " { " " to_regex ( field " " val " " false ) } } , 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 ( inner . into_iter ( ) . map ( | val | ( field , val ) . into_bson ( ) ) . collect :: < crate :: Result < Vec < _ > > > ( ) ? , ) } } doc ! { " " bson_values } } _ => doc ! { " " ( field PrismaValue List ( vals ) ) into_bson ( ) } , } , ScalarCondition :: NotIn ( vals ) => { doc ! { " " vals into_iter ( ) map ( val ( field val ) into_bson ( ) ) collect crate Result Vec ( ) } } ScalarCondition :: JsonCompare ( jc ) => match * jc . condition { ScalarCondition :: Equals ( value ) => { let bson = ( field , value ) . into_bson ( ) ? ; doc ! { " " bson } } ScalarCondition :: NotEquals ( value ) => { let bson = ( field , value ) . into_bson ( ) ? ; doc ! { " " bson } } _ => unimplemented ! ( " " ) , } , } ) }
Note contains / startsWith / endsWith are only applicable to String types in the schema.
Note contains / startsWith / endsWith are only applicable to String types in the schema .
field
&ScalarFieldRef
condition
ScalarCondition