FIRWriteBatch.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. @class FIRDocumentReference;
  19. @class FIRSetOptions;
  20. /**
  21. * A write batch is used to perform multiple writes as a single atomic unit.
  22. *
  23. * A WriteBatch object can be acquired by calling [FIRFirestore batch]. It provides methods for
  24. * adding writes to the write batch. None of the writes will be committed (or visible locally)
  25. * until [FIRWriteBatch commit] is called.
  26. *
  27. * Unlike transactions, write batches are persisted offline and therefore are preferable when you
  28. * don't need to condition your writes on read data.
  29. */
  30. NS_SWIFT_NAME(WriteBatch)
  31. @interface FIRWriteBatch : NSObject
  32. /** :nodoc: */
  33. - (id)init __attribute__((unavailable("FIRWriteBatch cannot be created directly.")));
  34. /**
  35. * Writes to the document referred to by `document`. If the document doesn't yet exist,
  36. * this method creates it and then sets the data. If the document exists, this method overwrites
  37. * the document data with the new values.
  38. *
  39. * @param data An `NSDictionary` that contains the fields and data to write to the document.
  40. * @param document A reference to the document whose data should be overwritten.
  41. * @return This `FIRWriteBatch` instance. Used for chaining method calls.
  42. */
  43. // clang-format off
  44. - (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
  45. forDocument:(FIRDocumentReference *)document NS_SWIFT_NAME(setData(_:forDocument:));
  46. // clang-format on
  47. /**
  48. * Writes to the document referred to by `document`. If the document doesn't yet exist,
  49. * this method creates it and then sets the data. If you pass `FIRSetOptions`, the provided data
  50. * will be merged into an existing document.
  51. *
  52. * @param data An `NSDictionary` that contains the fields and data to write to the document.
  53. * @param document A reference to the document whose data should be overwritten.
  54. * @param options A `FIRSetOptions` used to configure the set behavior.
  55. * @return This `FIRWriteBatch` instance. Used for chaining method calls.
  56. */
  57. // clang-format off
  58. - (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
  59. forDocument:(FIRDocumentReference *)document
  60. options:(FIRSetOptions *)options
  61. NS_SWIFT_NAME(setData(_:forDocument:options:));
  62. // clang-format on
  63. /**
  64. * Updates fields in the document referred to by `document`.
  65. * If document does not exist, the write batch will fail.
  66. *
  67. * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or
  68. * `FIRFieldPath`) and values with which to update the document.
  69. * @param document A reference to the document whose data should be updated.
  70. * @return This `FIRWriteBatch` instance. Used for chaining method calls.
  71. */
  72. // clang-format off
  73. - (FIRWriteBatch *)updateData:(NSDictionary<id, id> *)fields
  74. forDocument:(FIRDocumentReference *)document
  75. NS_SWIFT_NAME(updateData(_:forDocument:));
  76. // clang-format on
  77. /**
  78. * Deletes the document referred to by `document`.
  79. *
  80. * @param document A reference to the document that should be deleted.
  81. * @return This `FIRWriteBatch` instance. Used for chaining method calls.
  82. */
  83. - (FIRWriteBatch *)deleteDocument:(FIRDocumentReference *)document
  84. NS_SWIFT_NAME(deleteDocument(_:));
  85. /**
  86. * Commits all of the writes in this write batch as a single atomic unit.
  87. *
  88. * @param completion A block to be called once all of the writes in the batch have been
  89. * successfully written to the backend as an atomic unit. This block will only execute
  90. * when the client is online and the commit has completed against the server. The
  91. * completion handler will not be called when the device is offline, though local
  92. * changes will be visible immediately.
  93. */
  94. - (void)commitWithCompletion:(void (^)(NSError *_Nullable error))completion;
  95. @end
  96. NS_ASSUME_NONNULL_END