executeAverageQuery method

Future executeAverageQuery(
  1. {@required String field,
  2. @required AGConnectCloudDBQuery query,
  3. @required AGConnectCloudDBZoneQueryPolicy policy}
)

You can invoke this method to query Cloud DB zone object data that meets specified conditions and return the average value of specified fields.

Comply with the following rules when invoking this method:

  • You can invoke this method to query the average value of specified fields only when Cloud DB zone is opened. Otherwise, the query will fail.
  • Supports the following data types:
    • int for Short, Integer, and Long.
    • double for Double, and Float.

Implementation

Future<dynamic> executeAverageQuery({
  @required String field,
  @required AGConnectCloudDBQuery query,
  @required AGConnectCloudDBZoneQueryPolicy policy,
}) async {
  if (field == null || field.isEmpty) {
    throw FormatException('Value of field cannot be null or an empty string.', field);
  }
  if (query == null) {
    throw FormatException('Value of query cannot be null.', query);
  }
  if (policy == null) {
    throw FormatException('Value of policy cannot be null.', policy);
  }

  try {
    // Hint for null-safety: Return value can be null, int or double.
    return await _methodChannel.invokeMethod<dynamic>(
      MethodConstants.EXECUTE_AVERAGE_QUERY,
      <String, dynamic>{
        KeyConstants.ZONE_ID: this._id,
        KeyConstants.FIELD: field,
        KeyConstants.QUERY: query.query,
        KeyConstants.POLICY_INDEX: policy.index,
      },
    );
  } catch (e) {
    throw AGConnectCloudDBException.from(e);
  }
}