filter method

void filter(
  1. String filterString,
  2. Object? comparisonObject
)

Adds a filter to this Query.

filterString has form "name OP" where 'name' is a fieldName of the model and OP is an operator. The following operators are supported:

  • '<' (less than)
  • '<=' (less than or equal)
  • '>' (greater than)
  • '>=' (greater than or equal)
  • '=' (equal)

comparisonObject is the object for comparison.

Implementation

void filter(String filterString, Object? comparisonObject) {
  var parts = filterString.split(' ');
  if (parts.length != 2 || !_relationMapping.containsKey(parts[1])) {
    throw ArgumentError("Invalid filter string '$filterString'.");
  }

  var name = parts[0];
  var comparison = parts[1];
  var propertyName = _convertToDatastoreName(name);

  // This is for backwards compatibility: We allow [datastore.Key]s for now.
  // TODO: We should remove the condition in a major version update of
  // `package:gcloud`.
  if (comparisonObject is! ds.Key) {
    comparisonObject = _db.modelDB
        .toDatastoreValue(_kind, name, comparisonObject, forComparison: true);
  }
  _filters.add(ds.Filter(
      _relationMapping[comparison]!, propertyName, comparisonObject!));
}