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 =
        values != null && values.isNotEmpty
            ? await _pool.execute(Sql.named(query), parameters: values)
            : await _pool.execute(Sql(query));
    final rows = result.map((row) => row.toColumnMap()).toList();
    return DbResult(
      rows: rows,
      affectedRows: rows.length,
      executionTime: stopwatch.elapsed,
    );
  } catch (e) {
    throw Exception('PostgreSQL query failed: $e');
  }
}