Comparison Nodes

Comparison nodes are used to compare field values in query conditions.

Overview

Each comparison node inherits from QueryNode and evaluates whether a field in the item meets a specific condition.

Supported Comparison Nodes

Below is a list of all available comparison nodes and their behaviors.

Equality
  • FieldEquals(field, value, vType=auto_) True if the field equals the value.

  • FieldNotEquals(field, value, vType=auto_) True if the field does not equal the value.

Relational (Greater/Less)
  • FieldGreaterThan(field, value, vType=auto_) True if the field value is greater than the given value.

  • FieldGreaterThanOrEqual(field, value, vType=auto_) True if the field value is greater than or equal to the given value.

  • FieldLessThan(field, value, vType=auto_) True if the field value is smaller than the given value.

  • FieldLessThanOrEqual(field, value, vType=auto_) True if the field value is smaller than or equal to the given value.

Membership
  • FieldContains(field, value) True if the field (which must be a string or list) contains the given value.

  • FieldIn(field, list) True if the field’s value is included in the given list.

  • FieldNotIn(field, list) True if the field’s value is not included in the given list.

Pattern Matching
  • FieldMatchesRegex(field, pattern) True if the field’s value matches the regular expression.

  • FieldStartsWith(field, prefix) True if the field’s value starts with the specified prefix.

  • FieldEndsWith(field, suffix) True if the field’s value ends with the specified suffix.

vType (EnumValueType)

The equality and relational comparison nodes accept an optional vType parameter of type EnumValueType. This controls how both the field value and the comparison value are cast before the comparison is performed. If a cast fails (e.g. the value cannot be converted to the specified type), the result is always False.

Value

Behavior

auto_ (default)

Compares values as-is without any conversion.

datetime_

Parses both values as ISO 8601 strings and compares them as DateTime objects. If a DateTime object is passed directly as the value, this type is set automatically.

int_

Converts both values to integers before comparing.

floatStrict_

Converts both values to floating-point numbers and compares them exactly.

floatEpsilon12_

Converts both values to floating-point numbers and treats them as equal if the absolute difference is less than 1e-12.

boolean_

Converts both values to strings, lowercases them, and compares as booleans.

string_

Converts both values to strings and compares them.

stringIgnoreCase_

Converts both values to strings, lowercases them, and compares them (case-insensitive string comparison).

import 'package:delta_trace_db/delta_trace_db.dart';

// Case-insensitive string comparison
final node = FieldEquals('status', 'active',
    vType: EnumValueType.stringIgnoreCase_);
node.evaluate({'status': 'Active'});  // true
node.evaluate({'status': 'ACTIVE'});  // true

// Integer comparison (field stored as string)
final node2 = FieldGreaterThan('count', '10',
    vType: EnumValueType.int_);
node2.evaluate({'count': '20'});  // true
from delta_trace_db import FieldEquals, FieldGreaterThan, EnumValueType

# Case-insensitive string comparison
node = FieldEquals('status', 'active',
    v_type=EnumValueType.stringIgnoreCase_)
node.evaluate({'status': 'Active'})  # True
node.evaluate({'status': 'ACTIVE'})  # True

# Integer comparison (field stored as string)
node2 = FieldGreaterThan('count', '10',
    v_type=EnumValueType.int_)
node2.evaluate({'count': '20'})  # True

Examples

import 'package:delta_trace_db/delta_trace_db.dart';

final node = FieldGreaterThanOrEqual('score', 80);
final result = node.evaluate({'score': 85}); // true

final node2 = FieldLessThanOrEqual('age', 30);
final result2 = node2.evaluate({'age': 25}); // true
from delta_trace_db import FieldGreaterThanOrEqual, FieldLessThanOrEqual

node = FieldGreaterThanOrEqual('score', 80)
result = node.evaluate({'score': 85})  # True

node2 = FieldLessThanOrEqual('age', 30)
result2 = node2.evaluate({'age': 25})  # True

API