sortBy<T> method Null safety

  1. @override
void sortBy<T>(
  1. T propertyIdentifier(
    1. InstanceType x
    ),
  2. QuerySortOrder order
)
override

Configures this instance to sort its results by some property and order.

This method will have the database perform a sort by some property identified by propertyIdentifier. propertyIdentifier must return a scalar property of InstanceType that can be compared. The order indicates the order the returned rows will be in. Multiple sortBys may be invoked on an instance; the order in which they are added indicates sort precedence. Example:

    var query = Query<Employee>()
      ..sortBy((e) => e.name, QuerySortOrder.ascending);

Implementation

@override
void sortBy<T>(
  T Function(InstanceType x) propertyIdentifier,
  QuerySortOrder order,
) {
  final attribute = entity.identifyAttribute(propertyIdentifier);

  sortDescriptors ??= <QuerySortDescriptor>[];
  sortDescriptors!.add(QuerySortDescriptor(attribute.name, order));
}