@@ -217,6 +217,52 @@ impl<'a> WhereClause {
217
217
self . field == "$id"
218
218
}
219
219
220
+ /// Evaluate this clause against a provided `Value`
221
+ pub fn matches_value ( & self , value : & Value ) -> bool {
222
+ match & self . operator {
223
+ WhereOperator :: Equal => value == & self . value ,
224
+ WhereOperator :: GreaterThan => value > & self . value ,
225
+ WhereOperator :: GreaterThanOrEquals => value >= & self . value ,
226
+ WhereOperator :: LessThan => value < & self . value ,
227
+ WhereOperator :: LessThanOrEquals => value <= & self . value ,
228
+ WhereOperator :: In => match & self . value {
229
+ Value :: Array ( array) => array. contains ( value) ,
230
+ _ => false ,
231
+ } ,
232
+ WhereOperator :: Between => match & self . value {
233
+ Value :: Array ( bounds) if bounds. len ( ) == 2 => {
234
+ value >= & bounds[ 0 ] && value <= & bounds[ 1 ]
235
+ }
236
+ _ => false ,
237
+ } ,
238
+ WhereOperator :: BetweenExcludeBounds => match & self . value {
239
+ Value :: Array ( bounds) if bounds. len ( ) == 2 => {
240
+ value > & bounds[ 0 ] && value < & bounds[ 1 ]
241
+ }
242
+ _ => false ,
243
+ } ,
244
+ WhereOperator :: BetweenExcludeLeft => match & self . value {
245
+ Value :: Array ( bounds) if bounds. len ( ) == 2 => {
246
+ value > & bounds[ 0 ] && value <= & bounds[ 1 ]
247
+ }
248
+ _ => false ,
249
+ } ,
250
+ WhereOperator :: BetweenExcludeRight => match & self . value {
251
+ Value :: Array ( bounds) if bounds. len ( ) == 2 => {
252
+ value >= & bounds[ 0 ] && value < & bounds[ 1 ]
253
+ }
254
+ _ => false ,
255
+ } ,
256
+ WhereOperator :: StartsWith => {
257
+ if let ( Value :: Text ( text) , Value :: Text ( prefix) ) = ( value, & self . value ) {
258
+ text. starts_with ( prefix. as_str ( ) )
259
+ } else {
260
+ false
261
+ }
262
+ }
263
+ }
264
+ }
265
+
220
266
/// Returns the where clause `in` values if they are an array of values, else an error
221
267
pub fn in_values ( & self ) -> Result < Cow < Vec < Value > > , Error > {
222
268
let in_values = match & self . value {
0 commit comments