count method
Counts entities matching an optional query.
Convenience for the common readAll()/query().length pattern. Note it
hydrates the matching entities; for large datasets prefer a native count
via rawQuery with a COUNT(*) on a RawQueryCapable adapter.
Implementation
Future<int> count({
DatumQuery? query,
DataSource source = DataSource.local,
String? userId,
}) async {
_ensureInitialized();
if (query == null) {
final all = source == DataSource.local ? await localAdapter.readAll(userId: userId) : await remoteAdapter.readAll(userId: userId);
return all.length;
}
return (await this.query(query, source: source, userId: userId)).length;
}