performDocumentDelete method

  1. @override
Future<void> performDocumentDelete (
  1. DocumentDeleteRequest request
)
override

Implementation

@override
Future<void> performDocumentDelete(DocumentDeleteRequest request) async {
  final document = request.document;
  final collection = document.parent;
  final collectionId = _validateCollectionId(collection.collectionId);
  final documentId = _validateDocumentId(document.documentId);

  if (request.mustExist) {
    //
    // Check existence
    //
    final resp = await _apiRequest(
      method: 'GET',
      path: '/1/indexes/$collectionId/$documentId',
    );
    if (resp.statusCode == HttpStatus.notFound) {
      throw DatabaseException.notFound(document);
    }
  }

  //
  // Dispatch request
  //
  final apiResponse = await _apiRequest(
    method: 'DELETE',
    path: '/1/indexes/$collectionId/$documentId',
    isWrite: true,
  );

  //
  // Handle error
  //
  final error = apiResponse.error;
  if (error != null) {
    throw error;
  }
}