stream method
Reported when the stream finishes, with the rows it actually yielded.
Timing a stream at the call that creates it would report nothing; the interesting number is how long the consumer took to drain it.
Implementation
@override
Stream<MssqlStreamEvent> stream(
String sql, {
Object parameters = const <String, Object?>{},
MssqlQueryOptions options = MssqlQueryOptions.defaults,
Duration? timeout,
MssqlCancellationToken? cancellationToken,
int? batchRows,
int? maximumRows,
int? maximumBytes,
}) async* {
final stopwatch = Stopwatch()..start();
var rows = 0;
try {
await for (final event in inner.stream(
sql,
parameters: parameters,
options: options,
timeout: timeout,
cancellationToken: cancellationToken,
batchRows: batchRows,
maximumRows: maximumRows,
maximumBytes: maximumBytes,
)) {
if (event is MssqlRowBatch) rows += event.rows.length;
yield event;
}
} catch (error) {
stopwatch.stop();
_report(
MssqlQueryEvent(
sql: sql,
parameters: _visibleParameters(parameters),
elapsed: stopwatch.elapsed,
kind: MssqlOrmQueryKind.stream,
inTransaction: inner.inTransaction,
rows: rows,
failure: error,
compileElapsed: _takeCompileElapsed(this),
roundTrips: 1,
batchRows: batchRows ?? options.batchRows,
queryName: options.queryName,
),
);
rethrow;
}
stopwatch.stop();
_report(
MssqlQueryEvent(
sql: sql,
parameters: _visibleParameters(parameters),
elapsed: stopwatch.elapsed,
kind: MssqlOrmQueryKind.stream,
inTransaction: inner.inTransaction,
rows: rows,
compileElapsed: _takeCompileElapsed(this),
roundTrips: 1,
batchRows: batchRows ?? options.batchRows,
queryName: options.queryName,
),
);
}