batchWrite method

Future<BatchWriteResponse> batchWrite(
  1. BatchWriteRequest request,
  2. String session, {
  3. String? $fields,
})

Batches the supplied mutation groups in a collection of efficient transactions.

All mutations in a group are committed atomically. However, mutations across groups can be committed non-atomically in an unspecified order and thus, they must be independent of each other. Partial failure is possible, i.e., some groups may have been committed successfully, while some may have failed. The results of individual batches are streamed into the response as the batches are applied. BatchWrite requests are not replay protected, meaning that each mutation group may be applied more than once. Replays of non-idempotent mutations may have undesirable effects. For example, replays of an insert mutation may produce an already exists error or if you use generated or commit timestamp-based keys, it may result in additional rows being added to the mutation's table. We recommend structuring your mutation groups to be idempotent to avoid this issue.

request - The metadata request object.

Request parameters:

session - Required. The session in which the batch request is to be run. Value must have pattern ^projects/\[^/\]+/instances/\[^/\]+/databases/\[^/\]+/sessions/\[^/\]+$.

$fields - Selector specifying which fields to include in a partial response.

Completes with a BatchWriteResponse.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<BatchWriteResponse> batchWrite(
  BatchWriteRequest request,
  core.String session, {
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if ($fields != null) 'fields': [$fields],
  };

  final url_ = 'v1/' + core.Uri.encodeFull('$session') + ':batchWrite';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return BatchWriteResponse.fromJson(
      response_ as core.Map<core.String, core.dynamic>);
}