loadWhile<T extends Entity> method
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). Whentest
is called,lastLoaded
is the entity to test, andloaded
is a list of all loaded entities, includinglastLoaded
(at the end ofloaded
). Though rare, you can modifyloaded
intest
, such as removinglastLoaded
fromloaded
. -
whereClause
- if null, no where clause is generated. That is, the whole table will be loaded. Note: it shall not includewhere
. Example:"$fdType" = 23
-
fromClause
- if null, the entity's table is assumed. Note: it shall not includefrom
. Example:"$otTask" inner join "$otGrant"
-
shortcut
- the table shortcut to prefix the column names. Default: none. Useful if you joined other tables infromClause
. 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;
}