performDocumentInsert method

  1. @override
Future<void> performDocumentInsert(
  1. DocumentInsertRequest request
)
override

Inserts by using read and upsert operations inside a transaction.

Implementation

@override
Future<void> performDocumentInsert(DocumentInsertRequest request) {
  return performDocumentTransaction(DocumentTransactionRequest(
    callback: (transaction) async {
      final snapshot = await transaction.get(request.document);
      if (snapshot.exists) {
        throw DatabaseException.found(request.document);
      }
      await transaction.upsert(
        request.document,
        data: request.data,
      );
    },
    reach: request.reach,
    timeout: const Duration(seconds: 2),
  ));
}