streamSql<R> method

Stream<R> streamSql<R>(
  1. SqlQuery<R> query, {
  2. int batchSize = 128,
  3. ExecutionOptions options = const ExecutionOptions(),
})

Streams typed rows through the runtime's bounded cursor.

Finish or cancel before the borrowed session callback returns. Metadata is checked even for an empty result and decoder failures poison the active transaction through the same result guard as ordinary queries.

Implementation

Stream<R> streamSql<R>(
  SqlQuery<R> query, {
  int batchSize = 128,
  ExecutionOptions options = const ExecutionOptions(),
}) {
  final command = query.sql.compile(capabilities);
  R Function(List<Object?>)? decode;
  return streamRows(
    command,
    batchSize: batchSize,
    options: options,
    decode: (_, batch, _) async => _guardSqlResult(this, () {
      decode ??= query.result.bind(batch.columns);
      return [for (final row in batch.rows) decode!(row)];
    }),
  );
}