query<R> method

Future<List<R>> query<R>(
  1. SqlQuery<R> query, {
  2. ExecutionOptions options = const ExecutionOptions(),
  3. Iterable<TableSchema> changedTables = const [],
})

Executes once and decodes the actual metadata and rows. No wrapper or LIMIT is added. Use this for SELECT or native DML RETURNING.

Decode/mapper failures poison an explicit transaction even if caught. Outside a transaction, a write may already have committed before decoding fails; the ORM never automatically retries it.

Implementation

Future<List<R>> query<R>(
  SqlQuery<R> query, {
  ExecutionOptions options = const ExecutionOptions(),
  Iterable<TableSchema> changedTables = const [],
}) async {
  final command = query.sql.compile(capabilities);
  final result = await execute(
    command,
    options: options,
    changedTables: changedTables,
  );
  try {
    return observeDecode<List<R>>(command.sql, result.rows.length, () {
      final decode = query.result.bind(result.columns);
      return [for (final row in result.rows) decode(row)];
    });
  } catch (_) {
    if (inTransaction) markFailed();
    rethrow;
  }
}