onQueryEnd method

  1. @override
void onQueryEnd(
  1. QueryEndEvent event
)
override

Called after a query completes successfully.

Implementation

@override
void onQueryEnd(QueryEndEvent event) {
  if (event.duration < threshold) return;

  final buffer = StringBuffer();

  // Colorize duration based on time
  final ms = event.duration.inMilliseconds;
  final durationStr = '${ms}ms';
  final coloredDuration =
      colorize ? _colorDuration(durationStr, ms) : durationStr;

  // Operation prefix
  if (event.operation != null) {
    final opColor = colorize ? '\x1B[36m' : ''; // Cyan
    final reset = colorize ? '\x1B[0m' : '';
    final op = event.operation;
    buffer.write('$opColor[$op]$reset ');
  }

  buffer.write('[$coloredDuration] ');

  if (includeSql) {
    buffer.write(_truncateSql(event.sql));
  }

  buffer.write(' → ${event.rowCount} row${event.rowCount == 1 ? '' : 's'}');

  if (includeParameters && event.parameters.isNotEmpty) {
    buffer.write('\n  Params: ${_sanitizeParams(event.parameters)}');
  }

  print(buffer.toString());
}