where<T> method Null safety

  1. @override
QueryExpression<T, InstanceType> where<T>(
  1. T propertyIdentifier(
    1. InstanceType x
    )
)
override

Selects a property from the object being queried to add a filtering expression.

You use this property to add filtering expression to a query. The expressions are added to the SQL WHERE clause of the generated query.

You provide a closure for propertyIdentifier that returns a property of its argument. Its argument is always an empty instance of the object being queried. You invoke methods like QueryExpression.lessThan on the object returned from this method to add an expression to this query.

    final query = Query<Employee>()
      ..where((e) => e.name).equalTo("Bob");

You may select properties of relationships using this method.

    final query = Query<Employee>()
      ..where((e) => e.manager.name).equalTo("Sally");

Implementation

@override
QueryExpression<T, InstanceType> where<T>(
  T Function(InstanceType x) propertyIdentifier,
) {
  final properties = entity.identifyProperties(propertyIdentifier);
  if (properties.length != 1) {
    throw ArgumentError(
      "Invalid property selector. Must reference a single property only.",
    );
  }

  final expr = QueryExpression<T, InstanceType>(properties.first);
  expressions.add(expr);
  return expr;
}