rawQuery method
Executes a raw SQL query with optional named parameters.
If values
is non-empty, the query is parsed using Sql.named
.
Otherwise, a raw Sql
query is executed.
Returns a DbResult containing the resulting rows and query time.
Implementation
@override
Future<DbResult> rawQuery(
String query, {
Map<String, dynamic>? values,
}) async {
try {
final stopwatch = Stopwatch()..start();
final result =
values != null && values.isNotEmpty
? await _connection.execute(Sql.named(query), parameters: values)
: await _connection.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');
}
}