delete method

Future<int> delete(
  1. String? password,
  2. Resource? resource,
  3. Dstu2ResourceType? resourceType,
  4. Id? id,
  5. String? field,
  6. String? value,
)

Delete specific resource

Implementation

Future<int> delete(
  String? password,
  Resource? resource,
  Dstu2ResourceType? resourceType,
  Id? id,
  String? field,
  String? value,
) async {
  if ((resource != null && resource.resourceType != null) ||
      (resourceType != null && id != null) ||
      (resourceType != null && field != null && value != null)) {
    Finder finder;
    if (resource != null) {
      finder = Finder(filter: Filter.equals('id', '${resource.id}'));
    } else if (resourceType != null && id != null) {
      finder = Finder(filter: Filter.equals('id', '$id'));
    } else {
      finder = Finder(filter: Filter.equals(field!, value));
    }
    _setStoreType(ResourceUtils
        .resourceTypeToStringMap[resource?.resourceType ?? resourceType]!);
    return await _resourceStore.delete(await _db(password), finder: finder);
  } else {
    throw const FormatException('Must have either: '
        '\n1) a resource with a resourceType'
        '\n2) a resourceType and an Id'
        '\n3) a resourceType, a specific field, and the value of interest');
  }
}