upsert method

void upsert({
  1. Map<String, dynamic> body = const {},
  2. Map<String, dynamic> query = const {},
  3. List<MultipartFile> files = const [],
  4. Map<String, String> headers = const {},
  5. String? expand,
  6. String? fields,
})

Registers a record upsert request into the current batch queue.

The request will be executed as update if bodyParams have a valid existing record id value, otherwise - create.

Implementation

void upsert({
  Map<String, dynamic> body = const {},
  Map<String, dynamic> query = const {},
  List<http.MultipartFile> files = const [],
  Map<String, String> headers = const {},
  String? expand,
  String? fields,
}) {
  final enrichedQuery = Map<String, dynamic>.of(query);
  enrichedQuery["expand"] ??= expand;
  enrichedQuery["fields"] ??= fields;

  final request = _BatchRequest(
    method: "PUT",
    files: files,
    url: _batch.dummyClient
        .buildURL(
          "/api/collections/${Uri.encodeComponent(_collectionIdOrName)}/records",
          enrichedQuery,
        )
        .toString(),
    headers: headers,
    body: body,
  );

  _batch._requests.add(request);
}