withQueryCount<T> static method

Future<(T, int, List<QueryExecuted>)> withQueryCount<T>(
  1. FutureOr<T> body()
)

Runs body and returns its result, how many queries it ran and the queries themselves:

final (users, count, _) = await DB.withQueryCount(
  () => User.query().with_('posts').get(),
);
expect(count, 2); // eager loading: no N+1

Implementation

static Future<(T, int, List<QueryExecuted>)> withQueryCount<T>(
  FutureOr<T> Function() body,
) async {
  final (result, queries) = await manager.captureQueries(body);
  return (result, queries.length, queries);
}