executeQuery method
Future
executeQuery(
- String formatString,
- Map<
String?, dynamic> ? values, - int timeoutInSeconds, {
- PersistentStoreQueryReturnType? returnType = PersistentStoreQueryReturnType.rows,
override
Implementation
@override
Future<dynamic> executeQuery(
String formatString,
Map<String?, dynamic>? values,
int timeoutInSeconds, {
PersistentStoreQueryReturnType? returnType =
PersistentStoreQueryReturnType.rows,
}) async {
final now = DateTime.now().toUtc();
try {
final dbConnection = await executionContext;
dynamic results;
if (returnType == PersistentStoreQueryReturnType.rows) {
results = await dbConnection!.query(
formatString,
substitutionValues: values as Map<String, dynamic>?,
timeoutInSeconds: timeoutInSeconds,
);
} else {
results = await dbConnection!.execute(
formatString,
substitutionValues: values as Map<String, dynamic>?,
timeoutInSeconds: timeoutInSeconds,
);
}
logger.fine(
() =>
"Query (${DateTime.now().toUtc().difference(now).inMilliseconds}ms) $formatString Substitutes: ${values ?? "{}"} -> $results",
);
return results;
} on TimeoutException catch (e) {
throw QueryException.transport(
"timed out connection to database",
underlyingException: e,
);
} on PostgreSQLException catch (e) {
logger.fine(
() =>
"Query (${DateTime.now().toUtc().difference(now).inMilliseconds}ms) $formatString $values",
);
logger.warning(e.toString);
final interpreted = _interpretException(e);
if (interpreted != null) {
throw interpreted;
}
rethrow;
}
}