executeQuery method

  1. @override
Future executeQuery(
  1. String formatString,
  2. Map<String?, dynamic>? values,
  3. int timeoutInSeconds, {
  4. PersistentStoreQueryReturnType? returnType = PersistentStoreQueryReturnType.rows,
})
override

Implementation

@override
Future<dynamic> executeQuery(
    String formatString, Map<String?, dynamic>? values, int timeoutInSeconds,
    {PersistentStoreQueryReturnType? returnType =
        PersistentStoreQueryReturnType.rows}) async {
  var now = DateTime.now().toUtc();
  try {
    var 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;
  }
}