rawQuery method

  1. @override
Future<DbResult> rawQuery(
  1. String query, {
  2. Map<String, dynamic>? values,
})
override

Executes a raw SQL query and returns the result.

  • query: The SQL query to execute.
  • values: Optional named parameters for substitution (e.g., @name).

Implementation

@override
Future<DbResult> rawQuery(
  String query, {
  Map<String, dynamic>? values,
}) async {
  try {
    final stopwatch = Stopwatch()..start();
    final result = await _pool.execute(query, values ?? {});
    return DbResult(
      rows: result.rows.map((row) => row.assoc()).toList(),
      affectedRows: result.affectedRows.toInt(),
      insertId: result.lastInsertID,
      executionTime: stopwatch.elapsed,
    );
  } on DbException {
    rethrow;
  } catch (e) {
    throw _mapMySqlError(e);
  }
}