executeCountQuery method

Future<int> executeCountQuery({
  1. required String field,
  2. required AGConnectCloudDBQuery query,
  3. required AGConnectCloudDBZoneQueryPolicy policy,
})

You can call this method to search for Cloud DB zone objects that meet specified conditions and return the number of data records in a specified field. During statistics collection, if the value of this field is not empty, count 1. Otherwise, count 0.

Comply with the following rules when invoking this method:

  • This method is called to query the number of the specified fields only when Cloud DB zone is opened. Otherwise, the query will fail.
  • The startAt(), startAfter(), endAt(), and endBefore() methods cannot be used as query conditions.

Implementation

Future<int> executeCountQuery({
  required String field,
  required AGConnectCloudDBQuery query,
  required AGConnectCloudDBZoneQueryPolicy policy,
}) async {
  if (field.isEmpty) {
    throw FormatException('field cannot be an empty string.', field);
  }
  try {
    final int? result = await _methodChannel.invokeMethod<int>(
      _MethodConstants.EXECUTE_COUNT_QUERY,
      <String, dynamic>{
        _KeyConstants.ZONE_ID: _id,
        _KeyConstants.FIELD: field,
        _KeyConstants.QUERY: query.query,
        _KeyConstants.POLICY_INDEX: policy.index,
      },
    );
    return result!;
  } catch (e) {
    throw AGConnectCloudDBException._from(e);
  }
}