loadWhile<T extends Entity> method

  1. @deprecated
Future<List<T>> loadWhile<T extends Entity>(
  1. Iterable<String>? fields,
  2. T newInstance(
    1. String oid
    ),
  3. bool test(
    1. T lastLoaded,
    2. List<T> loaded
    ),
  4. String? whereClause, [
  5. Map<String, dynamic>? whereValues,
  6. String? fromClause,
  7. String? shortcut,
  8. AccessOption? option,
])

Loads entities while test returns true. It stops loading if all entities are loaded or test returns false.

Note: the last entity passed to test will be in the returned list unless you remove it in test. (that is, do ... while(test()))

  • test - it is called to test if the loading shall continue (true). When test is called, lastLoaded is the entity to test, and loaded is a list of all loaded entities, including lastLoaded (at the end of loaded). Though rare, you can modify loaded in test, such as removing lastLoaded from loaded.

  • whereClause - if null, no where clause is generated. That is, the whole table will be loaded. Note: it shall not include where. Example: "$fdType" = 23

  • fromClause - if null, the entity's table is assumed. Note: it shall not include from. Example: "$otTask" inner join "$otGrant"

  • shortcut - the table shortcut to prefix the column names. Default: none. Useful if you joined other tables in fromClause. Note: shortcut is case insensitive.

Implementation

@deprecated
Future<List<T>> loadWhile<T extends Entity>(
    Iterable<String>? fields, T newInstance(String oid),
    bool test(T lastLoaded, List<T> loaded),
    String? whereClause, [Map<String, dynamic>? whereValues,
    String? fromClause, String? shortcut, AccessOption? option]) async {

  final loaded = <T>[];

  await for (final row in queryFrom(
      fields != null ? (LinkedHashSet.from(fields)..add(fdOid)): null,
      fromClause ?? newInstance('*').otype,
      whereClause, whereValues, shortcut, option)) {

    final e = toEntityNS(row, fields, newInstance);
    loaded.add(e); //always add (i.e., add before test)
    if (!test(e, loaded))
      break;
  }

  return loaded;
}