executeDelete method

Future<int> executeDelete(
  1. {@required String objectTypeName,
  2. @required List<Map<String, dynamic>> entries}
)

You can call this method to delete a group of Cloud DB zone objects whose primary key values are the same as those of the input object list in batches. The delete operation focuses only on whether the primary key of the object is consistent, regardless of whether other attributes of the object match the stored data. The delete operation is atomic. That is, the input object list is either all deleted successfully or all fails to be deleted.

Returns the number of objects that are successfully deleted.

Comply with the following rules when invoking this method:

  • You can call this method to delete objects only when Cloud DB zone is opened. Otherwise, the delete operation fails.
  • When a group of objects is deleted, the total number of data records in the list must be less than or equal to 1000. Otherwise, the delete operation fails.
  • The data size of all objects in the list must be less than or equal to 2 MB. Otherwise, the delete operation fails.
  • The data size of all objects in the list must be less than or equal to 2 MB only when the data synchronization attribute is cache and the data persistency attribute is non-persistent.

Implementation

Future<int> executeDelete({
  @required String objectTypeName,
  @required List<Map<String, dynamic>> entries,
}) async {
  if (objectTypeName == null || objectTypeName.isEmpty) {
    throw FormatException('Value of objectTypeName cannot be null or an empty string.', objectTypeName);
  }
  if (entries == null || entries.isEmpty) {
    throw FormatException('Value of entries cannot be null or an empty list.', entries);
  }

  try {
    return await _methodChannel.invokeMethod<int>(
      MethodConstants.EXECUTE_DELETE,
      <String, dynamic>{
        KeyConstants.ZONE_ID: this._id,
        KeyConstants.ZONE_OBJECT_TYPE_NAME: objectTypeName,
        KeyConstants.ZONE_OBJECT_DATA_ENTRIES: entries,
      },
    );
  } catch (e) {
    throw AGConnectCloudDBException.from(e);
  }
}